Search code examples
iosswiftcore-animation

How to get Show segue's timing function and duration


I want to add an animation to my UIView so that it will move along with show segue. How do I get the default timing function and duration for show segue?

Here is my code:

let transition=CATransition()
transition.duration=0.4
transition.type=kCATransitionPush
transition.subtype=kCATransitionFromRight
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
myUIView.layer.addAnimation(transition, forKey: nil)

However my view's entering animation is not completely synchronized with the show segue's animation.


Solution

  • The easiest way is to use UIViewController's transitionCoordinator and call animateAlongsideTransition:completion: which is documented in UIViewControllerTransitionCoordinator. viewWillAppear is usually a good place to do this.

    You can then run any animations you want along with the default animation.