尝试在两个视图控制器之间使用自定义转换时遇到问题。在动画完成后运行解雇动画时,toView的帧原点将重置为(0,0):
呈现和解雇的代码是这样的:
class ConfirmEmailAnimator: NSObject, UIViewControllerAnimatedTransitioning {
let duration = 0.5
var dismiss = false
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return duration
}
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
if !dismiss {
let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
let toView = transitionContext.viewForKey(UITransitionContextToViewKey)!
let finalFrame = toView.frame
toView.frame.origin.x += transitionContext.containerView()!.frame.size.width
transitionContext.containerView()?.addSubview(toView)
//Animate out
UIView.animateWithDuration(duration, animations: { () -> Void in
fromView.frame.origin.x -= transitionContext.containerView()!.frame.size.width
toView.frame = finalFrame
}) { (Bool) -> Void in
transitionContext.completeTransition(true)
}
}
else {
let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)!
let toView = transitionContext.viewForKey(UITransitionContextToViewKey)!
transitionContext.containerView()!.addSubview(toView)
transitionContext.containerView()!.bringSubviewToFront(toView)
//Animate out
UIView.animateWithDuration(duration, animations: { () -> Void in
toView.center = transitionContext.containerView()!.center
fromView.center.x += 400
}) { (Bool) -> Void in
transitionContext.completeTransition(true)
}
}
}
}
任何想法我可能在这里做错了吗?只是希望视图动画回原来的位置,而不是(0,0)s