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?
Try this:
self.transition.timingFunction = CAMediaTimingFunction(controlPoints: 0.2, 0.9, 0.42, 1)
https://developer.apple.com/documentation/quartzcore/camediatimingfunction/1522235-init
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With