panyf07 panyf07 - 3 months ago 48
Objective-C Question

Tapping URL not work in TTTAttributedLabel while there is a UITapGestureRecognizer on its superview

There is container view and a

UITapGestureRecognizer
on it.And it also has a subview which kind of
TTTAttributedLabel
.

When I remove the gesture recognizer from container view, the delegate method of
TTTAttributedLabelDelegate


- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url can be called.


When I add the gesture recognizer on container view. Only its action method be called. The delegate method of
TTTAttributedLabelDelegate
won't be called.

Now I need delegate method to be called when I tap on a link in
TTTAttributedLabel
,and action method to called when I tap on other area of container view.

Thanks.

Answer

use this gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch for detection your event.

- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
      if ([touch.view isKindOfClass:[TTTAttributedLabel class]])
      {
           return FALSE;
      }
      else
      {

         return TRUE;
      }
}

you can also use if ([touch.view isKindOfClass:[UIControl class]]) for all UIControl e.g Button even detect with UIGestureRecognizer. hope this help's you