Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exact easing and timing for default UIViewController present animation

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?

like image 279
LulzCow Avatar asked Oct 29 '22 07:10

LulzCow


1 Answers

Try this:

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

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

like image 168
Adam Young Avatar answered Nov 15 '22 07:11

Adam Young