导航控制器当我们自定义了左侧返回功能的时候,就没有了边缘侧滑返回的功能,这时候我们只需要在我们的导航控制器中添加以下代码,就可以使其拥有边缘侧滑返回的功能了:
在ViewDidLoad中添加以下代码
id target = self.interactivePopGestureRecognizer.delegate;
UIPanGestureRecognizer* fullScreenGes = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
[self.view addGestureRecognizer:fullScreenGes];
fullScreenGes.delegate = self;
self.interactivePopGestureRecognizer.enabled = NO;
然后实现UIGestureRecognizerDelegate方法
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
//判断是否是根控制器
return self.childViewControllers.count>1;
}
只需要这简单的两部,就可以拥有像系统一样的侧滑返回功能了