本文主要是介绍开启UIViewController向右滑动实现返回的功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
要屏蔽/开启某一个UIViewController的系统自带的右滑手势实现返回的功能。如下步骤:
(1)在.m文件中实现如下代码:(一般写在viewDidLoad方法中)
- (void)viewDidLoad {[super viewDidLoad];if ([[UIDevice currentDevice].systemVersion floatValue]>=7.0) {if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {self.navigationController.interactivePopGestureRecognizer.enabled = YES;self.navigationController.interactivePopGestureRecognizer.delegate = self;} } }
(2)在此viewController的头文件中加入代理<UIGestureRecognizerDelegate>;
@interface BaseViewController ()<UIGestureRecognizerDelegate>@end
(2)实现代理方法
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{if ([self.navigationController.viewControllers count] == 1) {return NO;}else{return YES;}
}
这篇关于开启UIViewController向右滑动实现返回的功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!