简体   繁体   English

默认UIViewController呈现动画的确切缓动和时间

[英]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. 我正在尝试制作一个自定义的CATransition,以便推送一个viewController看起来与模态呈现一个完全相同。

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 这就是我从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. 我所拥有的与默认的UIViewController.present(vc,animated:true,completion:nil)动画并没有太大的不同,但它略有不同,尤其是缓动和消除动画。

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) self.transition.timingFunction = CAMediaTimingFunction(controlPoints:0.2,0.9,0.42,1)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM