iOS手势(滑动)返回的实现(自定义返回按钮)


如果各位使用的是storyboard布局的话,且用的是系统的返回按钮,那么是自动会有滑动返回效果的,但是相信各位做项目的,一般都是用的自定义的返回按钮,所以我贴几行代码,看看怎么实现系统自带的滑动返回的。
首先,建立一个自定义的返回按钮,然后加上去

  [self.navigationItem setLeftBarButtonItem:backBarItem];

然后

- (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; //代理置空,否则会闪退 if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.delegate = nil; } } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; //开启iOS7的滑动返回效果 if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { //只有在二级页面生效 if ([self.navigationController.viewControllers count] == 2) { self.navigationController.interactivePopGestureRecognizer.delegate = self; } } }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM