xcode popViewControllerAnimated:自定义过渡动画?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10553264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:17:17  来源:igfitidea点击:

popViewControllerAnimated: custom transition animation?

xcodeanimationuinavigationcontrollertransition

提问by Thromordyn

Yes, I have looked for an answer already. None of the solutions work, except one that doesn't give the option for a fade transition, only flip or curl.

是的,我已经在寻找答案了。除了不提供淡入淡出过渡选项,只能翻转或卷曲的解决方案之外,没有任何解决方案有效。

Like this:

像这样:

methodname
    configure animation
    [self.navigationController popViewControllerAnimated:NO];

No matter what variety of transition animation config I try, nothing is visibly different from only using the typical single-line pop. If I change it to …Animated:YES];, I get the standard pop animation, maybe with something weird happening from the broken config.

无论我尝试了何种过渡动画配置,都与仅使用典型的单行 pop 没有明显不同。如果我将其更改为…Animated:YES];,我会得到标准的流行动画,可能是由于损坏的配置发生了一些奇怪的事情。

So my question is this: How can I do a popwith, if not CrossDissolve, then at least something that looks the same? Is that even possible with a navigation controller?

所以我的问题是:pop如果没有CrossDissolve,我该如何做,那么至少看起来相同的东西?甚至可以使用导航控制器吗?

Using modal views would have the default animation I want, and I could manage the view stack easily enough, but I don't want to do that.

使用模态视图会有我想要的默认动画,我可以很容易地管理视图堆栈,但我不想这样做。

回答by Joris Kluivers

For this type of transition I would really recommend a modal view controller, thats the way the system was designed.

对于这种类型的转换,我真的会推荐一个模态视图控制器,这就是系统的设计方式。

But if you insist on using the navigation controller there is a way, though somewhat ugly.

但是如果你坚持使用导航控制器,有一种方法,虽然有点难看。

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];

CATransition *transition = [CATransition animation];
[transition setType:kCATransitionFade];
[self.navigationController.view.layer addAnimation:transition forKey:@"someAnimation"];

[self.navigationController popViewControllerAnimated:YES];
[CATransaction commit];

The CATransactionwill disable all standard animations. The CATransitionadds a fade transition to the navigation controller layer when views are swapped (in this case removing the viewcontroller view that is popped).

CATransaction将禁用所有标准的动画。的CATransition增加时的观点被交换淡入过渡到导航控制器层(在此情况下除去被弹出的视图控制器视图)。

回答by Jon

In iOS 7 above, you may want to look into UIViewControllerAnimatedTransitioningfor presented view controllers, or UINavigationControllerDelegatemethod :

在上面的 iOS 7 中,您可能需要查看UIViewControllerAnimatedTransitioning呈现的视图控制器或UINavigationControllerDelegate方法:

- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC

I have some sample code from another questionfor more info.

我有来自另一个问题的一些示例代码以获取更多信息。

回答by Axel Guilmin

Joris Kluivers's answer in Swift 3 :

Joris Kluivers 在 Swift 3 中的回答:

CATransaction.begin()
CATransaction.setDisableActions(true)

let animation = CATransition()
animation.type = kCATransitionFade
self.navigationController?.view.layer.add(animation, forKey: "someAnimation")
_ = self.navigationController?.popViewController(animated: false)

CATransaction.commit()