当按下一个新的viewController时,我创建了一个自定义的放大过渡,它过去可以正常工作。现在,我想在弹出viewController时创建一个缩小效果,甚至认为最终状态是正确的,动画是错误的,因为我不知道如何识别它是在推动还是弹出,以及诸如返回false,并且isBeingPresented始终为nil-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{ self.transitionContext = transitionContext; UIView *containerView = [transitionContext containerView]; UIViewController *fromViewController = (UIViewController *)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UIViewController *toViewController = (UIViewController *) [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; [containerView addSubview:toViewController.view]; CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; scaleAnimation.duration = [self transitionDuration:transitionContext]; scaleAnimation.delegate = self; scaleAnimation.removedOnCompletion = YES; CABasicAnimation *opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; opacityAnimation.duration = [self transitionDuration:transitionContext]; opacityAnimation.delegate = self; opacityAnimation.removedOnCompletion = YES; if (toViewController.isBeingPresented) { scaleAnimation.fromValue = [NSNumber numberWithDouble:0]; scaleAnimation.toValue = [NSNumber numberWithDouble:1]; opacityAnimation.fromValue = [NSNumber numberWithFloat:1]; opacityAnimation.toValue = [NSNumber numberWithFloat:0]; } else { scaleAnimation.fromValue = [NSNumber numberWithDouble:1]; scaleAnimation.toValue = [NSNumber numberWithDouble:0]; opacityAnimation.fromValue = [NSNumber numberWithFloat:0]; opacityAnimation.toValue = [NSNumber numberWithFloat:1]; } [toViewController.view.layer addAnimation:scaleAnimation forKey:nil]; [fromViewController.view.layer addAnimation:opacityAnimation forKey:nil];} (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 您可以保存一个UINavigationControllerOperation变量:-(id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController*)fromVC toViewController:(UIViewController*)toVC { self.navigationOperation = operation; return self;}然后检查它是推入式还是弹出式:if (self.navigationOperation == UINavigationControllerOperationPush) { // push} else if (self.navigationOperation == UINavigationControllerOperationPop) { // pop}关于ios - 自定义过渡iOS(推送/弹出),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30872886/ (adsbygoogle = window.adsbygoogle || []).push({});
10-10 04:50