QMUI中添加全屏手势,如果你使用了QM中的导航,是与FDFullscreenPopGesture存在冲突的,隐藏导航的处理冲突,FD会展示出导航,两者只能选其一,具体处理如下:
参考:
github.com/Tencent/QMU… github.com/Tencent/QMU…
1. 添加全屏手势
-(void)viewDidLoad{
[super viewDidLoad];
//这里需要注意:如果没有使用QM ,target=self.interactivePopGestureRecognizer.delegate
id target = self.qmui_interactivePopGestureRecognizerDelegate;
SEL handler = NSSelectorFromString(@"handleNavigationTransition:");
// 获取添加系统边缘触发手势的View
UIView *targetView = self.interactivePopGestureRecognizer.view;
// 创建pan手势 作用范围是全屏
UIPanGestureRecognizer *fullScreenGesture = [[UIPanGestureRecognizer alloc]initWithTarget:target action:handler];
fullScreenGesture.delegate = self;
[targetView addGestureRecognizer:fullScreenGesture];
self.fullScreenGesture = fullScreenGesture;
// 关闭边缘触发手势 防止和原有边缘手势冲突(不关闭处理过程中发现很多问题,直接给关闭了)
[self.interactivePopGestureRecognizer setEnabled:NO];
}
2.添加手势代理处理
// iOS 13.4 开始会优先询问该方法,只有返回 YES 后才会继续后续的逻辑(这里我没有做特殊处理)
- (BOOL)_gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveEvent:(UIEvent *)event {
return YES;
}
//这里处理手势逻辑
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
//这里由于是替代interactivePopGestureRecognizer 所以只识别右滑返回
if (gestureRecognizer == self.fullScreenGesture) {
CGPoint translation = [self.fullScreenGesture translationInView:self.fullScreenGesture.view];
if (translation.x > 0) {
//判断是否可以向右滑
BOOL canPopViewController = [self canPopViewController:self.topViewController byPopGesture:YES];
if (canPopViewController) return YES;
}
return NO;
}
return YES;
}
- (BOOL)canPopViewController:(UIViewController *)viewController byPopGesture:(BOOL)byPopGesture {
if (self.viewControllers.count > 1) {
//判断是否有拦截返回QMUI方法shouldPopViewControllerByBackButtonOrPopGesture,如果自定义方法也可以,不需要拦截情况下只判断self.viewControllers.count > 1 即可返回YES
if ([viewController respondsToSelector:@selector(shouldPopViewControllerByBackButtonOrPopGesture:)] &&
[viewController shouldPopViewControllerByBackButtonOrPopGesture:byPopGesture] == NO) {
return NO;
}
return YES;
}
return NO;
}