Swift Navigation Controller 轻扫以返回任何地方

标签 swift xcode uitableview uinavigationcontroller

我有一个带有嵌入式导航 Controller 的 View Controller ,我希望呈现的 Controller 能够在任何地方滑动以返回到根 Controller 。这怎么可能是通过使用 SwipeGesture 或扩展导航 Controller ?

另请注意,所呈现的 Controller 是一个表格 View 并且具有单元格 Nib 。

最佳答案

根据您的指示,您的 tableview 上的普通手势识别器就足够了。

我会做这样的事情:

override func viewDidLoad() {
    super.viewDidLoad()

    let gesture = UISwipeGestureRecognizer(target: self, action: #selector(dismiss(fromGesture:)))
    tableView.addGestureRecognizer(gesture)
}

@objc func dismiss(fromGesture gesture: UISwipeGestureRecognizer) {
    //Your dismiss code
    //Here you should implement your checks for the swipe gesture
}

如果您想禁用后退手势的默认行为:

navigationController?.interactivePopGestureRecognizer?.isEnabled = false

希望对您有所帮助。 :)

关于Swift Navigation Controller 轻扫以返回任何地方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43235219/

相关文章:

ios - 使用push方法后关闭viewController

ios - 重写 ManageObjectContext - 数据消失

ios - 从 InputStream 中获取数据

iphone - iOS : How to put some view on top of presented modal view controller?

ios - 如何将第三方框架导入到我的 Swift 项目中?

iphone - 带有自定义单元格的 tableView 上的 "Load more.."- 单元格重用导致我出现一些问题

ios - 滚动 UITableView 时单元格数据不正确

swift - iOS 11 大标题导航栏卡住而不是平滑过渡

ios - 更改 UITableViewCell ios 7.1.2 中默认删除按钮的颜色

ios - 使用 Swift 重新加载数据()