self.navigationController.interactivePopGestureRecognizer.enabled = YES;
如果手动定制了返回按钮,这个功能将会失效,也就是自定义了navigationItem的leftBarButtonItem,那么这个手势就会失效。
1.重新设置手势的delegate
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
实现代理
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
//关闭主界面的右滑返回
if (self.navigationController.viewControllers.count == 1)
{
return NO;
}
else
{
return YES;
}
}
2.当然你也可以自己响应这个手势的事件
[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(handleGesture:)];