[英]Unable to click “under” a hidden TabBar
我这样隐藏我的标签栏:
self.tabBarController.tabBar.hidden = YES;
并且因为现在有一个曾经竖立的黑条,所以我拉伸了一个视图,该视图是一个UIWebView
在顶部(或者它在下面?)那个空白区域。 UIWebView
在UIViewController
。 我这样做的约束默认情况下是这样的:
约束的代码:
if(self.tabBarController.tabBar.hidden){
self.webviewBottomConstrain.constant = -self.tabBarController.tabBar.frame.size.height;
}else{
self.webviewBottomConstrain.constant = 0;
}
但是,如果我在TabBar所在的位置点击设备,它将无法执行。 好像标签栏的大小在其中看不见。 我也尝试过将其隐藏起来以隐藏该线程 。 结果还是一样。
更新:似乎,当您点击不可见的标签栏时,标签栏会识别该点击,而不是由标签栏下方的视图识别
self.extendedLayoutIncludesOpaqueBars =是; 这将解决您的问题
您可以通过将其tabBar的hidden属性设置为NO来隐藏它? 尝试将其设置为“是”。 除非我误解了您要做什么,否则似乎您的选项卡栏没有被该代码隐藏。
我要检查的另一件事是查看是否为Web视图选中了“启用用户交互”。 如果不是,那似乎是某种看不见的东西阻碍了您与视图的交互。
好吧,我正在使用非常难看的hack来解决这个问题。 我现在以另一种方式隐藏标签栏:
if (shouldShow) {
self.hidesBottomBarWhenPushed = NO;
UIViewController *someView = [[UIViewController alloc] init];
[self.navigationController pushViewController:someView animated:NO];
[self.navigationController popToViewController:self animated:NO];
} else if (shouldHide) {
self.hidesBottomBarWhenPushed = YES;
self.tabBarController.hidesBottomBarWhenPushed = YES;
self.navigationController.hidesBottomBarWhenPushed = YES;
UIViewController *someView = [[UIViewController alloc] init];
[self.navigationController pushViewController:someView animated:NO];
[self.navigationController popToViewController:self animated:NO];
}
我确实需要那种随机视图,因为我无法将视图推向自身。
通过将标签栏移出屏幕底部来隐藏标签栏时,我遇到了同样的问题。 我的自定义UITabBarViewController拦截了选项卡栏腾出的区域中的触摸事件,因此,我没有改变选项卡栏的框架以将选项卡栏移到屏幕外,而是扩展了选项卡栏视图控制器的高度,以便选项卡栏仍然已移至屏幕外,但选项卡栏上方的子视图现在填充了该空间。 这允许子视图接收触摸。
如您在视图层次结构工具中可能看到的那样,UITabBar不会直接阻止您的点击,但是您当前视图控制器的视图高度不是全屏显示:
因此,点击不会响应,因为手指的y位置高于视图的maxY 。
像这样的代码(在UITabBarController内部)将根据标签栏的可见性扩展视图的高度,并且所有轻敲事件都将正常运行。
func updateTabBarAppearanceWithDegree(_ degree: CGFloat) {
let screenHeight = UIScreen.main.bounds.size.height
let tabBarHeight = self.tabBar.frame.size.height
self.tabBar.frame.origin.y = screenHeight - tabBarHeight * degree
self.tabBar.alpha = degree
let currentNavigation = self.selectedViewController as? UINavigationController
if let currentTopView = currentNavigation?.viewControllers.last?.view {
currentTopView.frame.size.height = self.tabBar.frame.origin.y
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.