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
popViewControllerAnimated: custom transition animation?
提问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 pop
with, 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 CATransaction
will disable all standard animations. The CATransition
adds 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 UIViewControllerAnimatedTransitioning
for presented view controllers, or UINavigationControllerDelegate
method :
在上面的 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()