是不是不能同时使用这两个?最初,我已经覆盖了(Swift)触摸在我的ViewController中开始/移动/结束。
现在,我想在特定情况下向某些视图添加一个 TapGestureRecognizer,但选择器/操作永远不会被触发。
class ViewController: UIViewController, UIGestureRecognizerDelegate {
...
func addTapGesturesOnNumberPadDisplay() {
if tapGestureRecognizerNumberPadView == nil {
tapGestureRecognizerNumberPadView = UITapGestureRecognizer(target: self, action: "handleTap:")
tapGestureRecognizerNumberPadView!.delegate = self
self.numberViewDone?.addGestureRecognizer(tapGestureRecognizerNumberPadView!)
}
}
...
func handleTap(sender: UITapGestureRecognizer) {
//never hit
这不可能吗?我应该只在触摸中实现我自己的点击功能开始了,因为我无论如何都要覆盖它,或者有没有办法在这里也使用 tapGestureRecognizer?
由于您在视图控制器中覆盖了触摸开始/移动/结束,因此它应该不会对其他子视图中的点击手势产生任何影响。理想情况下,它应该有效。请检查下面的代码,按预期工作。
class ViewController: UIViewController, UIGestureRecognizerDelegate {
@IBOutlet weak var categoryScrollView: UIScrollView!
var customView: UIView!
var tapGestureRecognizerNumberPadView : UITapGestureRecognizer?
override func viewDidLoad() {
super.viewDidLoad()
customView = UIView()
customView.frame.origin = CGPointMake(50,50)
customView.frame.size = CGSizeMake(100, 100)
customView.backgroundColor = UIColor.blueColor()
self.view.addSubview(customView)
addTapGesturesOnNumberPadDisplay()
}
func addTapGesturesOnNumberPadDisplay() {
if tapGestureRecognizerNumberPadView == nil {
tapGestureRecognizerNumberPadView = UITapGestureRecognizer(target: self, action: "handleTap:")
tapGestureRecognizerNumberPadView!.delegate = self
self.customView?.addGestureRecognizer(tapGestureRecognizerNumberPadView!)
}
}
func handleTap(sender: UITapGestureRecognizer) {
print("handleTap")
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
}
}
请检查是否有任何其他手势来查看"数字视图完成"。