subview 超出frame 点击事件无反应处理

demo.jpeg
重写hitTest方法:
/**
overwrite hitTest 解决子视图超出父试图frame 点击无法响应问题
@param point <#point description#>
@param event <#event description#>
@return <#return value description#>
*/
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *view = [super hitTest:point withEvent:event];
if (view == nil) {
//将坐标由当前视图发送到 指定视图 fromView是无法响应的范围小父视图
if (self.timeMenu) {
CGPoint stationPoint = [self.timeMenu.listTable convertPoint:point fromView:self];
if (CGRectContainsPoint(self.timeMenu.listTable.bounds, stationPoint)){
view = self.timeMenu.listTable;
}
}
if (self.numTimesMenu) {
CGPoint stationPoint = [self.numTimesMenu.listTable convertPoint:point fromView:self];
if (CGRectContainsPoint(self.numTimesMenu.listTable.bounds, stationPoint)) {
view = self.numTimesMenu.listTable;
}
}
}
return view;
}
本文标题:subview 超出frame 点击事件无反应处理
本文链接:https://www.haomeiwen.com/subject/ncepsftx.html
网友评论