1.添加代理
UIGestureRecognizerDelegate
2.在- (void)viewDidLoad中添加代碼
// 獲取系統(tǒng)自帶滑動手勢的target對象
idtarget =self.navigationController.interactivePopGestureRecognizer.delegate;
// 創(chuàng)建全屏滑動手勢,調(diào)用系統(tǒng)自帶滑動手勢的target的action方法
UIPanGestureRecognizer*pan = [[UIPanGestureRecognizeralloc]initWithTarget:targetaction:@selector(handleNavigationTransition:)];
// 設置手勢代理,攔截手勢觸發(fā)
pan.delegate=self;
// 給導航控制器的view添加全屏滑動手勢
[self.viewaddGestureRecognizer:pan];
// 禁止使用系統(tǒng)自帶的滑動手勢
self.navigationController.interactivePopGestureRecognizer.enabled=NO;

3.代理回調(diào)方法,設置防止一個子類返回事件
//防止導航控制器只有一個rootViewcontroller時觸發(fā)手勢
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer*)gestureRecognizer{
// 注意:只有非根控制器才有滑動返回功能,根控制器沒有。
// 判斷導航控制器是否只有一個子控制器,如果只有一個子控制器,肯定是根控制器
if(self.navigationController.childViewControllers.count==1){
// 表示用戶在根控制器界面,就不需要觸發(fā)滑動手勢,
returnNO;
}
returnYES;
}

4.返回方法實現(xiàn)
-(void)handleNavigationTransition:(UIPanGestureRecognizer*)g{
//返回事件
}
