UITapGestureRecognizer on UIView and Its Subview Respond Together When Subview Is Tapped

前端 未结 3 1104
一生所求
一生所求 2021-01-13 05:15

UITapGestureRecognizer is applied to both UIImageView and its subview (UITextView). However, when I tap on subview, the receiver becom

3条回答
  •  庸人自扰
    2021-01-13 06:09

    Try the following code:

    conform the <UIGestureRecognizerDelegate> to your class.

    set yourGesture.delegate = self;

    then add this delegate Method:

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
        // return YES (the default) to allow the gesture recognizer to examine the touch object, NO to prevent the gesture recognizer from seeing this touch object.
        if([touch.view isKindOfClass: [UITextView class]] == YES)] {
            return YES;
        }
        else {
            return NO;
        }
    }
    

    Hope it will solve your issue. Enjoy Coding..!!!!

提交回复
热议问题