モーダルのトランジションアニメーションを持つコントローラをモーダルにします。しかし、私がコントローラを却下しようとすると、プログラムがクラッシュします。 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