UIView的提供了这个方法:- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
1.创建CustomView继承自UIView :
CustomView.h
@property (strong,nonatomic)NSArray * passthroughViews;
@property (nonatomic)BOOL testHits;
-(BOOL) isPassthroughView: (UIView*) view;
CustomView.m
-(UIView*) hitTest:(CGPoint)point withEvent:(UIEvent *)event{
if(self.testHits){
return nil;
}
if(!self.passthroughViews
|| (self.passthroughViews && self.passthroughViews.count == 0)){
return self;
} else {
UIView *hitView = [super hitTest:point withEvent:event];