popViewControllerAnimated: custom transition animation?

橙三吉。 提交于 2019-12-29 06:21:10

问题


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.

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?

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.


回答1:


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).




回答2:


In iOS 7 above, you may want to look into UIViewControllerAnimatedTransitioning for presented view controllers, or UINavigationControllerDelegate method :

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

I have some sample code from another question for more info.




回答3:


Joris Kluivers's answer in 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()


来源:https://stackoverflow.com/questions/10553264/popviewcontrolleranimated-custom-transition-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!