向右轻扫以消除边缘尺寸

时间:2019-12-26 00:16:09

标签: ios swift uinavigationcontroller uikit

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

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

2 个答案:

答案 0 :(得分: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
            }
        }
    }

答案 1 :(得分:0)

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