Exact easing and timing for default UIViewController present animation
Asked Answered
B

1

6

I'm trying to make a custom CATransition such that pushing a viewController looks exactly the same as presenting one modally.

so far I have this for present

override func viewWillAppear(_ animated:Bool){
    super.viewWillAppear(animated)
    self.transition = CATransition()
    self.transition.duration = 0.4
    self.transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    self.transition.type = kCATransitionMoveIn
    self.transition.subtype = kCATransitionFromTop
    self.transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    self.navigationController?.view.layer.add(self.transition, forKey: nil)
}

And this for dismiss

override func viewWillDisappear(_ animated:Bool){
    super.viewWillDisappear(animated)
    self.transition.type = kCATransitionReveal
    self.transition.subtype = kCATransitionFromBottom
    self.navigationController?.view.layer.removeAllAnimations()
    self.transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    self.navigationController?.view.layer.add(self.transition, forKey: nil)
}

And this is how I push it from a navigationController

self.navigationController?.pushViewController(myViewController(), animated: false)

What I have is not extremely different from the default UIViewController.present(vc, animated: true, completion: nil) animation, but it's subtly different, especially the easing and the dismiss animation.

Does anyone know what exact values I can use to most closely replicate the animation I'm looking for?

Bringhurst answered 22/5, 2017 at 22:28 Comment(0)
F
2

Try this:

self.transition.timingFunction = CAMediaTimingFunction(controlPoints: 0.2, 0.9, 0.42, 1)

https://developer.apple.com/documentation/quartzcore/camediatimingfunction/1522235-init

Frontwards answered 7/9, 2019 at 1:27 Comment(1)
Not exact but close enough for me. Thanks!Samba

© 2022 - 2024 — McMap. All rights reserved.