边缘的pop返回手势:
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.purple
// 保留Pop手势
navigationController?.interactivePopGestureRecognizer?.delegate = self
navigationController?.interactivePopGestureRecognizer?.isEnabled = true
}
这些代码主要实在UINavigationController上添加
Swift全屏pop返回手势:
class CustomNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// 1.取出手势&view
guard let gesture = interactivePopGestureRecognizer else { return }
gesture.isEnabled = false
let gestureView = gesture.view
// 2.获取所有的target
let target = (gesture.value(forKey: "_targets") as? [NSObject])?.first
guard let transition = target?.value(forKey: "_target") else { return }
let action = Selector(("handleNavigationTransition:"))
// 3.创建新的手势
let popGes = UIPanGestureRecognizer()
popGes.maximumNumberOfTouches = 1
gestureView?.addGestureRecognizer(popGes)
popGes.addTarget(transition, action: action)
}
override func pushViewController(_ viewController: UIViewController, animated: Bool) {
viewController.hidesBottomBarWhenPushed = true
super.pushViewController(viewController, animated: animated)
}
}
OC POP手势返回:
- (void)viewDidLoad {
[super viewDidLoad];
id target = self.interactivePopGestureRecognizer.delegate;
UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:target action:@selector(handleNavigationTransition:)];
pan.delegate = self;
[self.view addGestureRecognizer:pan];
[self.interactivePopGestureRecognizer setEnabled:NO];
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
return self.childViewControllers.count == 1 ? NO : YES;
}