当我们在push出VC 后,只要在VC 中有下面代码是可以在VC的边缘用手势拖动返回去的
class VC: UIViewController,UIGestureRecognizerDelegate {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: true)
navigationController?.interactivePopGestureRecognizer?.delegate = self
navigationController?.interactivePopGestureRecognizer?.isEnabled = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(false, animated: true)
}
}
但要在所有push出的VC中需要在全屏拖动可以返回去,那么在使用UINavigationController处用CustomNC即可
import UIKit
class CustomNC: UINavigationController {
override func viewDidLoad() {
supe