導(dǎo)航控制器返回府蔗,網(wǎng)上已經(jīng)有開源的FDFullscreenPopGesture,屏幕本身邊緣也可以是可以側(cè)滑返回的,如果自己想簡單的時候也可以,首要要獲取控制器的interactivePopGestureRecognizer常侦,然后獲取手勢的delegate~
如下所示:
**2016-12-08 16:48:32.573FlyElephant[21021:320874] ****全屏手勢****:<UIScreenEdgePanGestureRecognizer: 0x7fc04d809fb0; state = Possible; delaysTouchesBegan = YES; view = <UILayoutContainerView 0x7fc04d805730>; target= <(action=handleNavigationTransition:, target=<_UINavigationInteractiveTransition 0x7fc04d8097c0>)>>**
**2016-12-08 16:48:32.573 FlyElephant[21021:320874] ****全屏手勢****Target:<_UINavigationInteractiveTransition: 0x7fc04d8097c0>**
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.title = @"FlyElephant";
[self.navigationController.navigationBar setBarTintColor:[UIColor greenColor]];
NSLog(@"全屏手勢:%@",self.navigationController.interactivePopGestureRecognizer);
NSLog(@"全屏手勢Target:%@",self.navigationController.interactivePopGestureRecognizer.delegate);
id target = self.navigationController.interactivePopGestureRecognizer.delegate;
// 創(chuàng)建全屏滑動手勢,調(diào)用系統(tǒng)自帶滑動手勢的target的action方法
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
pan.delegate = self;
// 給導(dǎo)航控制器的view添加全屏滑動手勢
[self.view addGestureRecognizer:pan];
// 禁止使用系統(tǒng)自帶的滑動手勢
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
// 根控制器不側(cè)滑返回
if (self.childViewControllers.count == 1) {
// 表示用戶在根控制器界面贬媒,就不需要觸發(fā)滑動手勢聋亡,
return NO;
}
return YES;
}