iOS监听侧滑返回

在我的界面上有一个加在keyWindow上的按钮。想在侧滑返回的时候像导航栏渐变消失。效果如下

2017-03-09 17_23_30.gif

核心代码

navigationController?.interactivePopGestureRecognizer?.addTarget(self, action: #selector(action))

func action(sender: UIScreenEdgePanGestureRecognizer) {
        switch sender.state {
        case .changed:
            let x = sender.translation(in: view).x
            let progress = 1 - x / view.frame.width
            postButton.alpha = progress
        default:
            UIView.animate(withDuration: 0.4) {
                self.postButton.alpha = 1
            }
        }
    }

Demo

你可能感兴趣的:(iOS监听侧滑返回)