我正在尝试自定义过渡动画.我创建了一个符合UIViewControllerAnimatedTransitioning的动画对象:
原文链接:https://www.f2er.com/swift/318977.htmlimport UIKit class ViewControllerAnimator: NSObject,UIViewControllerAnimatedTransitioning { let duration = 1.0 func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval { return duration } func animateTransition(transitionContext: UIViewControllerContextTransitioning) { let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)! //Animate out UIView.animateWithDuration(duration,animations: { () -> Void in fromView.frame.origin.x -= 200 }) { (Bool) -> Void in transitionContext.completeTransition(true) } } }
我在尝试设置fromView的框架时遇到错误.它试图强行解开零时崩溃.我在这做错了什么?为什么我的fromView没有?