[英]iOS presenting view controller animated as 'Push' (right-left animation)
Currently, I have a view controller presenting other view controller. 当前,我有一个显示其他视图控制器的视图控制器。 What I'm trying to do is to recreate the default animation used when pushing a view controller.
我想做的是重新创建推视图控制器时使用的默认动画。
My current approach is: 我当前的方法是:
FirstViewController
: FirstViewController
:
@IBAction private func push(sender: AnyObject) {
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("SecondViewController")
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
view.window?.layer.addAnimation(transition, forKey: kCATransition)
presentViewController(vc, animated: false, completion: nil)
}
SecondViewController
: SecondViewController
:
@IBAction private func pop(sender: AnyObject) {
let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromLeft
view.window?.layer.addAnimation(transition, forKey: kCATransition)
dismissViewControllerAnimated(false, completion: nil)
}
It is almost working, but I have a weird behaviour, I'm having a kind of black screen/flash when transitioning between view controllers. 它几乎可以正常工作,但是我有一个奇怪的行为,在视图控制器之间进行转换时,我有一种黑屏/闪光灯。 I already tried changing
window.backgroundColor
but it is not fixing the issue. 我已经尝试过更改
window.backgroundColor
但是它不能解决问题。
Thanks in advance 0_0... 在此先感谢0_0 ...
The trouble is merely that what you're doing is not how to customize the animation for a present/dismiss transition. 问题仅在于您在做什么,而不是如何为当前/关闭过渡自定义动画。 Apple has provided you with a clear, well-establish, official way to do that, and what you're doing is not it.
Apple为您提供了一种清晰,完善的官方方法来执行此操作,而您要做的不是。 You need to give your presented view controller a
transitioningDelegate
along with implementations of animationControllerForPresentedController:
and animationControllerForDismissedController:
, and implement the UIViewControllerAnimatedTransitioning protocol, possibly along with a custom UIPresentationController subclass. 您需要为呈现的视图控制器提供一个
transitioningDelegate
以及animationControllerForPresentedController:
和animationControllerForDismissedController:
实现,并实现UIViewControllerAnimatedTransitioning协议(可能还有一个自定义UIPresentationController子类)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.