需求背景:
在有tabbar的首页点击navigationbar的时间选择器,弹出时间选择器页面,tabbar隐藏,对时间选择器进行选择
难点:
tabbar隐藏之后,弹出来的时间选择器不能选择原来tabbar位置的地方,点击无响应
解决办法:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
if (!self.isUserInteractionEnabled || self.isHidden || self.alpha <= 0.01) {
return nil;
}
if ([self pointInside:point withEvent:event]) {
for (UIView *subView in [self.subviews reverseObjectEnumerator]) {
CGPoint convertedPoint = [subView convertPoint:point fromView:self];
UIView *hitTestView = [subView hitTest:convertedPoint withEvent:event];
if (hitTestView) {
return hitTestView;
}
}
return self;
} else {
for (UIView *subView in [self.subviews reverseObjectEnumerator]) {
CGPoint convertedPoint = [subView convertPoint:point fromView:self];
UIView *hitTestView = [subView hitTest:convertedPoint withEvent:event];
if (hitTestView) {
return hitTestView;
}
}
return nil;
}
return nil;
}
重写controller的view的hittest方法,让其在点击tabbar的位置时进行相应
另外,在controller的loadview方法里,load重写的这一个view
- (void)loadView
{
MJHomeControllerView *view = [[MJHomeControllerView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.view = view;
}
网友评论