我正在尝试从TapGestureRecognizer中排除子视图。 它已在sotryboard中创建,代理连接到控制器。
在我的ViewControler中,我有GestureRecognizerDelegate协议,我设置了我的gesture.delegate = self。
虽然shouldReceiveTouch Gesturerecognizer函数没有调用,但是有什么想法吗?
这是代码的主题:
class DetailedPostViewController: UIViewController, UITextViewDelegate, MKMapViewDelegate, UIGestureRecognizerDelegate {
let circularLike = CircularLike(frame: CGRectZero)
@IBOutlet var gesture: UITapGestureRecognizer!
override func viewDidLoad() {
super.viewDidLoad()
gesture.delegate = self
self.view.addSubview(circularLike)
circularLike.frame = self.view.bounds
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if touch.view!.isDescendantOfView(circularLike){
return false
}
return true
}
@IBAction func UserTap(sender: AnyObject) {
if fromUser {
dismissViewControllerAnimated(true, completion: nil)
} else {
performSegueWithIdentifier("userPage", sender: nil)
}
}
@IBAction func hideUnhide(sender: UIGestureRecognizer) {
if hide {
hide=false
unhideUi()
} else {
hide = true
hideUi()
}
}
}
答案 0 :(得分:0)
好的,事实上,我只需要将我的子视图userTouchEnabled参数设置为false,然后它就会触发ShouldRecieveTouch函数......