美文网首页
自定义view阻止父视图手势响应

自定义view阻止父视图手势响应

作者: 迷路的字母C | 来源:发表于2017-06-30 17:35 被阅读94次

子类化UIView是,如果需要响应事件,会重现一系列touch方法,但是如果该自定义的View的父视图添加有手势的话,会出现自定义View事件与手势事件同时触发的现象。
解决办法是在自定义的UIView中重写

// called when the recognizer attempts to transition out of UIGestureRecognizerStatePossible if a touch hit-tested to this view will be cancelled as a result of gesture recognition
// returns YES by default. return NO to cause the gesture recognizer to transition to UIGestureRecognizerStateFailed
// subclasses may override to prevent recognition of particular gestures. for example, UISlider prevents swipes parallel to the slider that start in the thumb
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer NS_AVAILABLE_IOS(6_0);

返回YES。父视图的手势就不会触发了。

相关文章

网友评论

      本文标题:自定义view阻止父视图手势响应

      本文链接:https://www.haomeiwen.com/subject/wqjicxtx.html