向右滑动以消除边缘尺寸

问题描述 投票:0回答:2

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

即是否可以从屏幕中间向右轻扫以移动和弹出当前顶部ViewController,方法与从屏幕左边缘相同?

ios swift uinavigationcontroller uikit
2个回答
0
投票

    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
            }
        }
    }


0
投票

最后,找到了使用此库来增加边缘触摸大小的解决方案:SwipeTransition

© www.soinside.com 2019 - 2024. All rights reserved.