iOS 为自定义返回按钮leftBarButtonItem的页面添加右滑返回功能

来源:互联网 发布:处理器调度算法实现 编辑:程序博客网 时间:2024/05/20 20:51

在iOS7中,新增加了一个小小的功能
也就是这个api:
self.navigationController.interactivePopGestureRecognizer.enabled = YES;

但是通常情况下我们会自定义返回按钮,这种情况下,这个功能就会失效,也就是自定义了navigationItem的leftBarButtonItem,这个手势就会失效。


首先让VIewController遵守 UIGestureRecognizerDelegate协议

1.重新设置手势的delegate
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;

当然,在添加右滑返回的时候会遇见一个大坑,就是当退到NavigationController的rootViewController的时候继续右滑的话会遇见界面卡死的问题,解决这个问题的方法也很简单。

2.在rootViewController的viewDidAppear方法里面添上

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

3.在其他的ViewController的viewWillAppear方法里加上

self.navigationController.interactivePopGestureRecognizer.enabled = YES;

这句话的作用是禁止使用右滑手势。


毕竟右滑返回手势只能靠近屏幕左边缘才能使用~我们如何通过调用系统方法来实现在整个屏幕右滑就可以实现返回功能呢~
敷贴一个别人的链接。

全屏滑动返回

0 0
原创粉丝点击