方法一:
iOS 側(cè)滑返回功能舶沿,自定義手勢(shì)觸發(fā)系統(tǒng)的pop動(dòng)畫(huà)碴巾。handleNavigationTransition:為系統(tǒng)私有API,系統(tǒng)自帶的側(cè)滑手勢(shì)觸發(fā)的回調(diào)溯捆,并且可以從頁(yè)面任意地方滑動(dòng)。
#import "ViewController.h"
@interface ViewController ()<UIGestureRecognizerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
id target = self.navigationController.interactivePopGestureRecognizer.delegate;
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
panGesture.delegate = self; // 設(shè)置手勢(shì)代理厦瓢,攔截手勢(shì)觸發(fā)
[self.view addGestureRecognizer:panGesture];
// 禁止系統(tǒng)自帶的滑動(dòng)手勢(shì)
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
// 當(dāng)前控制器是根控制器時(shí)不觸發(fā)手勢(shì)
if(self.navigationController.childViewControllers.count == 1)
{
return NO;
}
return YES;
}
@end
方法二:
使用系統(tǒng)自帶的側(cè)滑:從邊緣滑動(dòng)提揍。
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
就醬...