在我的ViewController中,我有一個UIScreenEdgeGestureRecognizer
用於切換視圖,但也有一個UITableView
用於定製UITableViewCell
。在這個定製UITableViewCell
是一個UIPanGestureRecognizer
刷卡細胞。檢測UIScreenEdgeGestureRecognizer並失敗UIPanGestureRecognizer
我加了gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
所以兩個手勢都在工作,並且gestureRecognizerShouldBegin
可以防止垂直滾動的衝突。
問題是,我怎麼能給UIScreenEdgeGestureRecognizer
優先?當我在屏幕邊緣滑動時,我想切換視圖而不移動單元格。我想我應該使用委託方法,但到目前爲止,我讀得越多,我越感到困惑。
override func viewDidload() {
var recognizer = UIPanGestureRecognizer(target: self, action: "handlePan:")
recognizer.delegate = self
addGestureRecognizer(recognizer)
}
override func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
return true
}
override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
if let panGesture = gestureRecognizer as? UIPanGestureRecognizer {
let velocity = panGesture.velocityInView(superview!)
if fabs(velocity.x) > fabs(velocity.y) { return true }
return false
}
return false
}
的ViewController:
定製UITableViewCell
代碼
override func viewDidLoad() {
let rightScreenEdgeRecognizer = EdgePanGesture(target: self, action: "changeView:")
rightScreenEdgeRecognizer.edges = .Right
view.addGestureRecognizer(rightScreenEdgeRecognizer)
}
我也試過標識與識別:
gestureRecognizer.isKindOfClass(UIScreenEdgePanGestureRecognizer)
和
gestureRecognizer as? UIScreenEdgePanGestureRecognizer
但都失敗了。