子类化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。父视图的手势就不会触发了。