簡體   English   中英

無法單擊隱藏的TabBar“下方”

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

我這樣隱藏我的標簽欄:

self.tabBarController.tabBar.hidden = YES;

並且因為現在有一個曾經豎立的黑條,所以我拉伸了一個視圖,該視圖是一個UIWebView在頂部(或者它在下面?)那個空白區域。 UIWebViewUIViewController 我這樣做的約束默認情況下是這樣的:

在此處輸入圖片說明

約束的代碼:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM