背景: 我以前在视图上有一个触摸手势检测器,它工作正常。 然后我的应用程序增长了,现在我需要将相同的手势检测器添加到3个视图中。
问题: 当我将手势检测器添加到视图中时,手势检测器从未被调用,该视图已使用" .addSubview"
附加到父视图守则:
parentView.addSubview(waveview)
parentView.addSubview(waveviewCap)
parentView.addSubview(waveviewCapBG)
let singleFingerDTap:UITapGestureRecognizer=UITapGestureRecognizer.init(target: self, action: "handleWaveviewTap")
singleFingerDTap.numberOfTapsRequired = 1;
self.waveview!.addGestureRecognizer(singleFingerDTap)
self.waveviewCap!.addGestureRecognizer(singleFingerDTap)
self.waveviewCapBG!.addGestureRecognizer(singleFingerDTap)
答案 0 :(得分:0)
请在父视图中添加UIGestureRecognizerDelegate。并更新" shouldReceiveTouch"委托方法。
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if touch.view == waveview || touch.view == waveviewCap || touch.view == waveviewCapBG {
return true
}
return false
}
希望它的工作......