有时当用户返回到之前的 UIViewController
时,我想做点什么。
如果用户点击了 UINavigationBar
中的后退按钮,我可以捕获该事件。
但如果他们使用滑动返回手势返回,我无法响应更改。
那么滑动返回手势有回调吗?
目前我只能通过以下方式在我的应用中禁用这种页面
interactivePopGestureRecognizer.enabled = NO;
最佳答案
最简单的方法是通过执行以下操作来连接到已经内置到 UINavigationController
中的那个:
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.interactivePopGestureRecognizer?.addTarget(self, action: #selector(MyViewController.handleBackswipe))
}
@objc private func handleBackswipe() {
navigationController?.interactivePopGestureRecognizer?.removeTarget(self, action: #selector(MyViewController.handleBackswipe))
// insert your custom code here
}
请记住在您的选择器中调用 removeTarget(_:action:)
,否则它将向您的选择器发送垃圾邮件,直到手势结束。
关于ios - 在 iOS 中是否有向后滑动手势的回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32005718/