先描述一下侧滑的整个流程:
1.系统自带有侧滑功能,但是只能在边缘处滑动;系统是怎么实现的呢?
2.现在分析一下,当屏幕发生侧滑手势时,控制器会先询问代理,navigationbar的左上角的item是否改变!如果改变,则不执行手势,如果没有改变,则代理会调用handleNavigationTransition:方法,实现侧滑手势;
3.现在,我们先分析一下:如果在控制器询问代理的navigationbar左上角的item是否改变的时候,我们直接不让他询问代理,而是直接调用handleNavigationTransition:方法……这样就能实现不管左上角是否修改,都会执行侧滑手势;
4.再进一步分析,我们自己模仿他的代理,自己添加手势,然后调用handleNavigationTransition:方法,则可以实现全局侧滑功能;
1.系统自带的手势是UIScreenEdgePanGestureRecognizer类型对象,屏幕边缘滑动手势
3.系统自带手势target是_UINavigationInteractiveTransition类型的对象
4.target调用的action方法名叫handleNavigationTransition:
@interface UINavigationController()<UIGestureRecognizerDelegate,UINavigationControllerDelegate>
@end
@implementation UINavigationController
-(void)viewDidLoad{
id taget = self.interactivePopGestureRecognizer.delegate;
UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc] initWithTarget:taget action:@selector(handleNavigationTransition:)];
pan.delegate = self;
self.interactivePopGestureRecognizer.delegate = nil;
[self.view addGestureRecognizer:pan];
}
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
return (self.childViewControllers.count != 1);
}
@end