系統(tǒng)自帶的右滑返回只有從邊緣才有效,而我們希望從屏幕任何地方都可以右滑返回。
在基類導航控制器BaseNavigationController里面做處理
// 獲取系統(tǒng)自帶滑動手勢的target對象
id target = self.interactivePopGestureRecognizer.delegate;
// 創(chuàng)建全屏滑動手勢,調(diào)用系統(tǒng)自帶滑動手勢的target的action方法
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:target action:@selector(handleNavigationTransition:)];
// 設(shè)置手勢代理,攔截手勢觸發(fā)
pan.delegate = self;
// 給導航控制器的view添加全屏滑動手勢
[self.view addGestureRecognizer:pan];
// 禁止使用系統(tǒng)自帶的滑動手勢
self.interactivePopGestureRecognizer.enabled = NO;
效果圖
screenshot.gif
Demo:
https://github.com/guanzhendong/ScreenEdgePanGestureDemo