Je modale un contrôleur avec une animation de transition modale. Mais quand j'essaie de rejeter le contrôleur, le programme plante. Et Xcode n'a enregistré aucun message.iOS crash quand j'essaie de rejeter un modal
C'est un problème avec mon animation de transition. Quand je supprime le code de transition, il fonctionne bien.
alors quel est le problème avec mon code?
- (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];
}
Merci! J'ai été confondu avec ce problème depuis longtemps. – hecong