ios - 向右滑动可关闭边缘尺寸

标签 ios swift uinavigationcontroller uikit

是否可以增加 UINavigationController 的边缘大小 interactivePopGestureRecognizer 来响应用户触摸?

即是否可以从屏幕中间向右滑动来移动并弹出当前顶部 View Controller ,方式与从屏幕左边缘相同?

最佳答案


    override func viewDidLoad() {
        super.viewDidLoad()
        let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
        swipeRight.direction = .right
        self.view.addGestureRecognizer(swipeRight)

        let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(respondToSwipeGesture))
        swipeLeft.direction = .left
        self.view.addGestureRecognizer(swipeLeft)

    }

    // you can track all direction swipe like below, and to do that first you have to add gesture in the view you want to track.
    @objc func respondToSwipeGesture(gesture: UIGestureRecognizer) {
        if let swipeGesture = gesture as? UISwipeGestureRecognizer {
            switch swipeGesture.direction {
            case .right:
                // push pop here
                print("Swiped right")
            case .down:
                print("Swiped down")
            case .left:
                // push pop here
                print("Swiped left")
            case .up:
                print("Swiped up")
            default:
                break
            }
        }
    }

关于ios - 向右滑动可关闭边缘尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59482739/

相关文章:

ios - Ios8 中的 UIActionsheet

ios - 使用 .Value 和 .ChildAdded 检索数据

uiviewcontroller - 当我插入具有不同支持方向的 Controller 时,为什么 UINavigationController 不改变方向?

ios - 尝试透明时导航 Controller 黑色

ios - 设置 navigationItem 标题延迟问题

iphone - 从 IOS 应用程序注销的完美方法是什么?

ios - 重写 UIView 子类中的 drawRect 方法并将其调用到另一个 UIViewcontroller 中

ios - 在 iPad 和 iPhone 之间更改表格 View 的行高大小

ios - URL 中的parameterString NSURL 的等效项

ios - 使用 swift 在 UITableView 中显示文本字段文本