Skip to content

Instantly share code, notes, and snippets.

@ahmattox
Created March 6, 2012 14:13
Show Gist options
  • Save ahmattox/1986482 to your computer and use it in GitHub Desktop.
Save ahmattox/1986482 to your computer and use it in GitHub Desktop.
UIViewSubclass which lets touches pass through it but not it's subviews.
//
// TouchThroughView.h
// Created by Anthony Mattox on 3/5/12.
//
#import <UIKit/UIKit.h>
@interface TouchThroughView : UIView
@property (nonatomic) BOOL touchThrough;
@end
//
// TouchThroughView.m
// Created by Anthony Mattox on 3/5/12.
//
#import "TouchThroughView.h"
@implementation TouchThroughView
@synthesize touchThrough;
- (BOOL) pointInside:(CGPoint) point withEvent:(UIEvent *) event {
if (touchThrough) {
if ([super pointInside:point withEvent:event]) {
for (UIView* subview in self.subviews) {
if (!subview.hidden && [subview pointInside:[self convertPoint:point toView:subview] withEvent:event]) {
return YES;
}
}
}
return NO;
}
return [super pointInside:point withEvent:event];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment