andreamazz / BubbleTransition

A custom modal transition that presents and dismiss a controller with an expanding bubble effect.
MIT License
3.32k stars 250 forks source link

Wrong Frame Starting Center when Translucent is False #53

Closed alexookah closed 5 years ago

alexookah commented 5 years ago

When using navigation bar with Translucent = False the starting point of the animation is calculated wrong.

Check the following video: https://streamable.com/gs9rn

Check my forked repo to reproduce: https://github.com/Alexookah/BubbleTransition

changes: i added a navigation controller as initial vc and changed the translucency in the navigation Bar.

andreamazz commented 5 years ago

The center is user provided, so you just need to adjust it like this:

  func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    transition.transitionMode = .present
    transition.startingPoint = view.convert(transitionButton.center, to: nil)
    transition.bubbleColor = transitionButton.backgroundColor!
    return transition
  }

  func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    transition.transitionMode = .dismiss
    transition.startingPoint = view.convert(transitionButton.center, to: nil)
    transition.bubbleColor = transitionButton.backgroundColor!
    return transition
  }

Notice the call to convert to get the absolute position.