1
我模態控制器與模態過渡動畫。但是,當我試圖解僱控制器時,程序崩潰。而且Xcode沒有記錄任何消息。iOS崩潰時,我試圖解僱模態
我的過渡動畫出現問題。當我刪除轉換代碼時,它運行良好。
那麼我的代碼有什麼問題?
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
_transitionContext = transitionContext;
UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];
UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];
CALayer *toVcLayer = [CALayer layer];
toVcLayer.frame = toView.layer.frame;
[toVcLayer addSublayer:toView.layer];
_transformLayer = [CATransformLayer layer];
_transformLayer.frame = [UIScreen mainScreen].bounds;
[_transformLayer addSublayer:fromView.layer];
CATransform3D ct = CATransform3DIdentity;
ct = CATransform3DMakeTranslation(0.0, 0.0, -1.0);
ct = CATransform3DRotate(ct, M_PI, 0.0, 1.0, 0.0);
toVcLayer.transform = ct;
[_transformLayer addSublayer:toVcLayer];
CATransform3D at = CATransform3DIdentity;
at = CATransform3DRotate(at, M_PI, 0.0, 1.0, 0.0);
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
animation.toValue = [NSValue valueWithCATransform3D:at];
animation.duration = 1.0;
animation.delegate = self;
[_transformLayer addAnimation:animation forKey:nil];
[transitionContext.containerView.layer addSublayer:_transformLayer];
}
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
[_transitionContext.containerView addSubview:[_transitionContext viewForKey:UITransitionContextToViewKey]];
[_transitionContext completeTransition:YES];
}
謝謝!很長一段時間我一直困惑這個問題。 – hecong