Bigair Bigair - 27 days ago 20
iOS Question

How to enable touch only on subviews

I have two views. A base view "View A" and its subview "View B"

I implemented tap gesture on View A and I want to enable that gesture only on View B, not View B which has actual gesture implementation.

View B may be transformed by GCAffineTransform( angle may be set ).

enter image description here

Answer

Make class conforming to UIGestureRecognizerDelegate.

Then make self as the UITapGestureRecognizer delegate.

Implement the below method.

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(nonnull UITouch *)touch {

  if (touch.view.tag == tagOfBlueView) {
    return YES;
  }
  return NO;
}
Comments