简体   繁体   中英

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. The UIWebView is in a UIViewController . 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. 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; this will solve you problem

You hide your tabBar by setting its hidden property to 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. 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. 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. 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:

带标签栏的视图排列

So, the tap doesn't response because your finger's y position is higher than view's maxY .

Code like this (inside your UITabBarController) will expand your view's height, according to tabbar visibility, and all tap events will work correctly.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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