视图侧滑手势返回上一级视图状态控制
2022-04-27 本文已影响0人
survivorsfyh
视图侧滑返回上一级视图手势控制的开启(默认开启状态)与关闭控制,具体 code 如下:
作用域可以在所需视图的 viewDidAppear 和 viewWillDisappear 中进行对其控制;
开启侧滑返回
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
关闭侧滑返回
if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
代理相关 UIGestureRecognizerDelegate
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer == self.navigationController.interactivePopGestureRecognizer) {
NSLog(@"AAAAAA --- %ld", [self.navigationController.viewControllers count]);// visibleViewController
if (self.navigationController.viewControllers.count < 2 || self.navigationController.visibleViewController == self.navigationController.viewControllers.firstObject) {
return NO;
} else {
return NO;
}
} else {
return YES;
}
}
以上便是此次分享的全部内容,希望能对大家有所帮助!