Adding an action to back swipes swift 4

瘦欲@ 提交于 2019-12-06 07:57:20

Like this answer you can just subscribe to the gesture: https://stackoverflow.com/a/36893464/1484378

// In UINavigationController

override func viewDidLoad() {
    super.viewDidLoad()
    self.interactivePopGestureRecognizer?.addTarget(self, action:#selector(self.handlePopGesture))
}

@objc func handlePopGesture(gesture: UIGestureRecognizer) -> Void {
    if gesture.state == .began {
        back()
    }
}

You will probably have to add some custom logic to access your view controller's back method like: if let vc = visibleViewController as? MyViewController { vc.back() }

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!