在透明的UIView中重写下面这个函数即可:
OC:
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
UIView *hitView = [super hitTest:point withEvent:event];
if(hitView == self){
return nil;
}
return hitView;
}
Swift:
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let hitView = super.hitTest(point, with: event)
if(hitView == self){
return nil
}
return hitView
}
纯属个人笔记,如有错误,欢迎指出。