简体   繁体   English

无法单击隐藏的TabBar“下方”

[英]Unable to click “under” a hidden TabBar

I hide my tab bar like so: 我这样隐藏我的标签栏:

self.tabBarController.tabBar.hidden = YES;

And because now there is a black bar where it once stood I stretch the view which is a UIWebView on top(or is it under?) that empty space. 并且因为现在有一个曾经竖立的黑条,所以我拉伸了一个视图,该视图是一个UIWebView在顶部(或者它在下面?)那个空白区域。 The UIWebView is in a UIViewController . UIWebViewUIViewController I do that with a constraint which by default is like so: 我这样做的约束默认情况下是这样的:

在此处输入图片说明

The code for the constraint: 约束的代码:

if(self.tabBarController.tabBar.hidden){
    self.webviewBottomConstrain.constant = -self.tabBarController.tabBar.frame.size.height;
}else{
    self.webviewBottomConstrain.constant = 0;
}

However if I tap the device on the place where the TabBar was it will not execute. 但是,如果我在TabBar所在的位置点击设备,它将无法执行。 It is as if there is something invisible there with the size of the tab bar. 好像标签栏的大小在其中看不见。 I have also tried hiding it the way this thread sugests . 我也尝试过将其隐藏起来以隐藏该线程 Still the same result. 结果还是一样。

Update: It seems that when you tap on the invisible tab bar the tap is recognized by the tab bar and not by the view that is visible under the tab bar 更新:似乎,当您点击不可见的标签栏时,标签栏会识别该点击,而不是由标签栏下方的视图识别

self.extendedLayoutIncludesOpaqueBars = YES; self.extendedLayoutIncludesOpaqueBars =是; this will solve you problem 这将解决您的问题

You hide your tabBar by setting its hidden property to NO? 您可以通过将其tabBar的hidden属性设置为NO来隐藏它? Try setting it to YES. 尝试将其设置为“是”。 Unless I am misunderstanding what you are trying to do, it seems like your tab bar is not hidden with that code. 除非我误解了您要做什么,否则似乎您的选项卡栏没有被该代码隐藏。

Another thing I would check is to see if User Interaction Enabled is checked for the web view. 我要检查的另一件事是查看是否为Web视图选中了“启用用户交互”。 If it is not, that can seem like there is something invisible blocking you from interacting with your view. 如果不是,那似乎是某种看不见的东西阻碍了您与视图的交互。

Well I am using quite ugly hack to fix this. 好吧,我正在使用非常难看的hack来解决这个问题。 I am hiding the tab bar in another way now: 我现在以另一种方式隐藏标签栏:

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];
}

I do need that random view because I cannot push the view on itself. 我确实需要那种随机视图,因为我无法将视图推向自身。

I had the same issue when hiding the tab bar by moving it offscreen to the bottom. 通过将标签栏移出屏幕底部来隐藏标签栏时,我遇到了同样的问题。 My custom UITabBarViewController was intercepting the touch events in the area vacated by the tab bar, so instead of changing the frame of the tab bar to move the tab bar offscreen, I extended the height of my tab bar view controller so that the tab bar still moved offscreen, but the child view above the tab bar now filled that space. 我的自定义UITabBarViewController拦截了选项卡栏腾出的区域中的触摸事件,因此,我没有改变选项卡栏的框架以将选项卡栏移到屏幕外,而是扩展了选项卡栏视图控制器的高度,以便选项卡栏仍然已移至屏幕外,但选项卡栏上方的子视图现在填充了该空间。 This allowed the touches to be received by the child view. 这允许子视图接收触摸。

As you may see with view hierarchy instrument, UITabBar is not directly blocking your tap, but your current view controller's view height is not full screen: 如您在视图层次结构工具中可能看到的那样,UITabBar不会直接阻止您的点击,但是您当前视图控制器的视图高度不是全屏显示:

带标签栏的视图排列

So, the tap doesn't response because your finger's y position is higher than view's maxY . 因此,点击不会响应,因为手指的y位置高于视图的maxY

Code like this (inside your UITabBarController) will expand your view's height, according to tabbar visibility, and all tap events will work correctly. 像这样的代码(在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM