Skip to content

Could I know overlay position changes realtime #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FrankWuoO opened this issue Dec 28, 2020 · 2 comments
Closed

Could I know overlay position changes realtime #78

FrankWuoO opened this issue Dec 28, 2020 · 2 comments

Comments

@FrankWuoO
Copy link

Hi there!
I'm trying to make interaction with other views in sync with the overlay transition and maybe is same issue with #42

Here is my implementation, I put detect point code in

func overlayContainerViewController(_ containerViewController: OverlayContainerViewController, willTranslateOverlay overlayViewController: UIViewController, transitionCoordinator: OverlayContainerTransitionCoordinator) {
    print("Moving")
    transitionCoordinator.animate { (context) in
    } completion: { (context) in
          let point = self.view.convert(overlayViewController.view.frame.origin, from: overlayViewController.view)
          let limit: CGFloat = kTopDistance + self.view.safeAreaInsets.top
          var offset: CGFloat = 0.0
          if point.y < limit {
              offset = limit - point.y
          }
          self.topContainerTopConstraint.constant = -offset
    }
}

It works fine with using finger to drag overlay, but when I slide up the overlay quickly or call containerVC.moveOverlay(toNotchAt: 2, animated: true), it's jump a little bit.

I checked the code and found that delegate didn't call this method overlayContainerViewController(_ containerViewController: OverlayContainerViewController, willTranslateOverlay overlayViewController: UIViewController, transitionCoordinator: OverlayContainerTransitionCoordinator) continuously

I've attached a video.

Record.mov
@gaetanzanella
Copy link
Contributor

gaetanzanella commented Dec 28, 2020

Hi @FrankWuoO

The transitions can be animated. In that case, the delegate method will be called only once when the transition starts. You can detect them using the OverlayContainerTransitionCoordinatorContext.isAnimated property.

I would move your logic to the animate block and use the context.targetTranslationHeight property to know where the container will be instead of the current overlay position:

func overlayContainerViewController(_ containerViewController: OverlayContainerViewController, willTranslateOverlay overlayViewController: UIViewController, transitionCoordinator: OverlayContainerTransitionCoordinator) {
    transitionCoordinator.animate(alongsideTransition: { (context) in
          let offset = ... // based on `context.targetTranslationHeight`
          self.topContainerTopConstraint.constant = -offset
          if context.isAnimated {
              self.view.layoutIfNeeded() // to animate the layout update
          }
    }, completion: nil)
}

@FrankWuoO
Copy link
Author

@gaetanzanella Cool!! You save my day.
Thanks for your answer. 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants