在项目中经常遇到这样的需求,屏幕被分成几个区域,并且每个区域都有很多不定时外部事件,要求层次分明互不影响,这个时候对UIview的触摸事件控制就很重要,下面是一个例子:
1.创建一个UIView的基础类,PBaseView,它的.m文件实现:
@implementation PBaseView
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
UIView *hitView = [super hitTest:point withEvent:event];
if(hitView == self){
return nil;
}
return hitView;
}
@end
2.创建三个子view,都继承于PBaseView,分别为PFirstView、PSecondView、PthirdView,其中一个PFirstView.m如下图:
@interface PFirstView()
@property (nonatomic, strong)UIViewController *superVc;
@end
@implementation PFirstView
- (instancetype)initWithFrame:(CGRect)frame superVc:(UIViewController *)superVc{