如何设置有两个边缘的UIScreenEdgePanGestureRecognizer

时间:2018-10-31 15:35:28

标签: ios swift swipe gesture edges

当用户从左侧或右侧滑动时,我想设置EdgePanGesture来更改ViewController。 仅从一个方向来看,它就可以完美运行:

func addingEdgePanDetection() {
    let edgePan = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(screenEdgeSwiped))
    edgePan.edges = .left
    view.addGestureRecognizer(edgePan)
}

但是,正如您可以在Apple的文档中看到的那样,UIRectEdge类型是UIRectEdge类型,它符合OptionSet协议,因此

  

您可以将这些常量加在一起,以在   同时。

我尝试了三种不同的想法,但都没有成功:

1.- edgePan.edges = [UIRectEdge.left, UIRectEdge.right]
2.- edgePan.edges = UIRectEdge.left | UIRectEdge.right
3.- edgePan.edges = UIRectEdge(rawValue: UIRectEdge.left.rawValue | UIRectEdge.right.rawValue)

有什么主意吗?我正在寻找一个只有一个actionRecognizer的答案。谢谢!

1 个答案:

答案 0 :(得分:2)

使用两个不同的import tensorflow as tf; print(tf.__version__) >>1.11.0 允许用户从左右方向滑动。

UIScreenEdgePanGestureRecognizer

在ViewDidLoad中:

var screenLeftEdgeRecognizer: UIScreenEdgePanGestureRecognizer!
var screenRightEdgeRecognizer: UIScreenEdgePanGestureRecognizer!

实践:

我已经在左,右,上,下,screenLeftEdgeRecognizer = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(rotateBall(_:))) screenLeftEdgeRecognizer.edges = .left view.addGestureRecognizer(screenLeftEdgeRecognizer) screenRightEdgeRecognizer = UIScreenEdgePanGestureRecognizer(target: self, action: #selector(rotateBall(_:))) screenRightEdgeRecognizer.edges = .right view.addGestureRecognizer(screenRightEdgeRecognizer) 等所有情况下尝试了您以前尝试过的方法。但是,即使未调用目标操作方法,也未成功。