导航控制器中的后退按钮动画
CATransitions 可用于在向下钻取时为导航控制器中的过渡设置动画。但是,当使用后退按钮和导航控制器(返回)时,动画仍然滑出。有谁知道如何将 CATransition 附加到导航控制器的后退按钮?谢谢。
“向下钻取”时用于动画的代码:
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
CATransitions can be used to animate transitions in Navigation Controllers when drilling down. However when using Back button og Navigation Controller (going back up) animation is still slide out. Does anyone know how to attach CATransition to the Back button of Navigation Controller? thanks.
Code used to animate when "drilling down":
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不需要创建自定义按钮...您可以简单地执行以下操作:
编辑:您必须首先添加石英框架才能使用 CATransition
There is no need to create a custom button... You can simply do something like this:
Edit: you must add the quartz framework first in order to use CATransition
要向后退按钮添加动画,您必须创建自己的后退按钮,并在后退按钮操作上指定所需的动画。
向导航栏添加后退按钮:将此行添加到您的 viewDidLoad 方法中:
在后退方法中添加以下代码:
For adding animation to the back button, you have to create your own back button, and on the back button action specify the animation you want.
Adding a back button to the navigation bar: add this line to your viewDidLoad method:
In the back method add this code:
我不确定我是否理解这个问题。
UINavigationController
在切换视图时已经使用了幻灯片转换。如果您想将自定义转换附加到后退按钮,则必须创建一个自定义后退按钮并将其连接到将运行您的 CATransition 代码的操作。I'm not sure I understand the question.
UINavigationController
already uses a slide transition when switching views. If you want to attach a custom transition to the back button, you're going to have to create a custom back button and connect it to an action that will run yourCATransition
code.如果您想要像导航控制器栏的后退按钮这样的动画,只需将以下代码放入您的操作中即可。
[self.navigationController popViewControllerAnimated:YES];
If you want animation like back button of navigation controller bar just put following code in your action.
[self.navigationController popViewControllerAnimated:YES];
Swift 3 版本的 Shadowfax 答案:
Swift 3 version of shadowfax answer: