Swift Swipe Gesture识别器具有重叠的UIViews

时间:2016-08-17 03:37:18

标签: ios swift uiview swipe gesture

我有两个UIViews,他们分别工作得很好。然而,一旦UIView下部重叠,UIView 2就不会在上部UIView 1覆盖的区域中注册?

UIView 1(品红色)重叠UIView 2(石灰)

enter image description here

UIView 1(品红色)接受向左/向右滑动。

UIView 2(lime)接受向上/向下滑动。

UIView 2(lime)显示没有重叠的UIView 1(品红色) enter image description here

@IBOutlet weak var swipeAB: UIView! 
@IBOutlet weak var swipeBC: UIView! 

func calculateAB(sender:UISwipeGestureRecognizer) {
    print("Swiped right, A to B")
}
func calculateBA(sender:UISwipeGestureRecognizer) {
    print("Swipe left, B to A")
}
func calculateBC(sender:UISwipeGestureRecognizer) {
    print("Swiped down, B to C")
}
func calculateCB(sender:UISwipeGestureRecognizer) {
    print("Swipe up, C to B")
}

override func viewDidLoad() {
    super.viewDidLoad()
    moveAB.addTarget(self, action: #selector(GameViewController.calculateAB))
    moveAB.direction = .Right
    swipeAB.addGestureRecognizer(moveAB)
    moveBA.addTarget(self, action: #selector(GameViewController.calculateBA))
    moveBA.direction = .Left
    swipeAB.addGestureRecognizer(moveBA)
    moveBC.addTarget(self, action: #selector(GameViewController.calculateBC))
    moveBC.direction = .Down
    swipeBC.addGestureRecognizer(moveBC)
    moveCB.addTarget(self, action: #selector(GameViewController.calculateCB))
    moveCB.direction = .Up
    swipeBC.addGestureRecognizer(moveCB)
}

1 个答案:

答案 0 :(得分:1)

impression7vx,你当场了,谢谢!

我把两个重叠的UIViews分成了:

  • UIView 1(品红色)检测向右滑动
  • UIView 2(黄色)检测向左滑动并向下滑动
  • UIView 3(lime)检测向上滑动

Split into 3 UIView