4
func addSwipe() {
self.isUserInteractionEnabled = true
let directions: [UISwipeGestureRecognizerDirection] = [.right, .left]
for direction in directions {
let gesture = UISwipeGestureRecognizer(target: self, action: #selector(ViewCardContainer.handleSwipe(sender:)))
gesture.direction = direction
self.addGestureRecognizer(gesture)
}
}
@objc func handleSwipe(sender: UISwipeGestureRecognizer) {
print(sender.direction)
}
我的UIViews輕掃手勢:UISwipeGestureRecognizer不承認視野之外發起
+----------------+
| |
| +--------+ |
| V1 | V2 | |
+-----------------
我註冊了UISwipeGestureRecognizer在V2但如果滑動手勢從V1開始通過V2去,滑動手勢贏在V2中不會被識別。
有沒有辦法讓它工作?提前致謝!
這是因爲您的輕掃手勢已註冊爲V1而非V2。您可以嘗試檢測從V1啓動的手勢的觸摸位置是否低於V2並調用一些更改 – Woof