你需要重载hitttest,在整个范围内(包括空白)都调用subviews。
解决方案:
让控件复写 -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event方法。 只有控件存在无论可见度是什么uikit框架会递归回调此接口。
若要subview响应touch事件,只需判断point是否在subview控件区域内,若在则返回此subview。若不在则返回nil。
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
BOOL isinView = NO;
UIView *clickView = nil;
for (UIView *showView in self.currentShowItemViewArray)
{
CGRect rect = showView.frame;
if ([showView isKindOfClass:[MyTabBarView class]])
rect = showView.bounds;
isinView = CGRectContainsPoint(rect , point);
if (isinView)
{
clickView = showView;
break;
}
}
if (isinView)
return clickView;
return nil;
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (CGRectContainsPoint(_rightButton.frame , point))
{
return _rightButton;
}
else if(CGRectContainsPoint(_shootButton.frame , point))
{
return _shootButton;
}
else if(CGRectContainsPoint(_leftButton.frame , point))
{
return _leftButton;
}
return nil;
}