Ignore touches to UIView subclass, but not to its subviews

vectorvector:

If you want a UIView subclass to ignore touch events, just set its userInteractionEnabled property to NO. But that will block touches to all its subviews. To ignore touches in a UIView subclass, but not its subviews, just work a little hitTest magic:

-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    id hitView = [super hitTest:point withEvent:event];
    if (hitView == self) return nil;
    else return hitView;
}
8 notes

  1. macotoi reblogged this from cocoaheads
  2. objectivesea reblogged this from vectorvector
  3. sidearms reblogged this from cocoaheads
  4. cocoaheads reblogged this from vectorvector
  5. vectorvector posted this