【问题标题】:Slide Back Gesture on Nav Bar with Left Bar Button使用左栏按钮在导航栏上滑动返回手势
【发布时间】:2019-07-01 20:28:55
【问题描述】:

我希望能够滑回导航栏上具有左栏按钮的视图控制器。

有很多 Stack Overflow 帖子解决了这个问题,而且大部分都说使用后退按钮项而不是左栏按钮,但这不是我想要使用的。使用这行代码:

self.navigationController?.interactivePopGestureRecognizer?.delegate = 无

允许您在使用左栏按钮时保留向后滑动手势,但最终会导致许多随机 UI 问题。我在想有可能通过使用平移手势识别器来保留后滑动手势,但我不确定如何去做,这就是滑出菜单往往会做的事情。

任何帮助都会很棒!

【问题讨论】:

  • 你现有的代码是什么样的?

标签: swift uinavigationcontroller uinavigationbar uigesturerecognizer


【解决方案1】:

尝试将 swipeGesture 添加到您的视图中,如下所示:

let swipeRightGesture = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.handleSwipeGesture(_:))

swipeRightGesture.direction = UISwipeGestureRecognizerDirection.right

view.addGestureRecognizer(swipeRightGesture

您的handleSwipeGesture() 方法应该包含弹出您的ViewController 的代码。

如果您希望滑动手势出现在 NavigationBar 上,请添加如下手势:

navigationController.navigationBar.addGestureRecognizer(swipeRightGesture)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-19
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    • 2019-04-13
    • 1970-01-01
    相关资源
    最近更新 更多