Bigair Bigair - 1 year ago 123
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 Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download