转载自:
作者:ysamg
来源:CSDN
原文:https://blog.csdn.net/ysamg/article/details/26683017
版权声明:本文为博主原创文章,转载请附上博文链接!
在项目中需要对导航跳转方式自定义,马上就能想到用
CATransition动画来实现,
下面的代码是跳转到下一个视图:
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType: kCATransitionPush];
[animation setSubtype: kCATransitionFromRight];//跳转方向样式
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.navigationController pushViewController:searchResult animated:NO];//禁止导航动画
[self.navigationController.view.layer addAnimation:animation forKey:@"animation"];
只需把导航的动画禁掉,加上自己所需要的方向
下面的代码是返回前一个视图:
CATransition *animation = [CATransition animation];
[animation setDuration:0.3];
[animation setType: kCATransitionPush];
[animation setSubtype: kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.navigationController.view.layer addAnimation:animation forKey:@"animation"];
self.navigationController popViewControllerAnimated:NO];//禁止动画
返回前一个视图时有个注意点,禁止动画这一句必须写在动画代码的后面,否则达不到理想的效果。
网友评论