[英]How to hide UITabBar?
在我的應用程序中,我有一個標簽欄。 在某些視圖中,我也有一個工具欄。 因此,當我使用工具欄訪問這些視圖時,它看起來很丑 - 視圖底部有兩個條。 我認為在輸入這些特定視圖時隱藏標簽欄是最好的解決方案。 但我只是不知道如何以正確的方式做到這一點。 我試圖將 UITabBarController 的 tabBar 隱藏屬性設置為 YES,但它不起作用。 無論我是什么觀點,我也試圖做以下事情:
self.hidesBottomBarWhenPushed = YES;
但它也沒有奏效。
這種情況的正確解決方案是什么? 我不想在任何角度都有 2 個酒吧。
您必須在要推送的控制器上將 hidesBottomBarWhenPushed 屬性設置為 YES,而不是將其設置為 UITabBarController。
otherController.hidesBottomBarWhenPushed = YES;
[navigationController pushViewController: otherController animated: TRUE];
或者您可以在首次初始化要推送的控制器時設置該屬性。
界面構建器具有嵌入在選項卡欄中的視圖控制器復選框 - 在推送時隱藏底部欄。 在簡單的情況下,現在不需要通過代碼來完成。
對於@Micah
我也為此掙扎了一段時間。 隱藏標簽欄是朝着正確方向邁出的一步,但會留下一個黑色矩形。 訣竅是調整支持 UIViewController 視圖的層的大小。
我在這里寫了一個帶有解決方案的小演示:
https://github.com/tciuro/FullScreenWithTabBar
我希望這有幫助!
不要使用此解決方案!
BOOL hiddenTabBar;
UITabBarController *tabBarController;
- (void) hideTabBar {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
for(UIView *view in tabBarController.view.subviews)
{
CGRect _rect = view.frame;
if([view isKindOfClass:[UITabBar class]])
{
if (hiddenTabBar) {
_rect.origin.y = [[UIScreen mainScreen] bounds].size.height-49;
[view setFrame:_rect];
} else {
_rect.origin.y = [[UIScreen mainScreen] bounds].size.height;
[view setFrame:_rect];
}
} else {
if (hiddenTabBar) {
_rect.size.height = [[UIScreen mainScreen] bounds].size.height-49;
[view setFrame:_rect];
} else {
_rect.size.height = [[UIScreen mainScreen] bounds].size.height;
[view setFrame:_rect];
}
}
}
[UIView commitAnimations];
hiddenTabBar = !hiddenTabBar;
}
沒有內置的方法可以隱藏當前視圖的標簽欄。
您可以在使用hidesBottomBarWhenPushed
變量推送視圖時隱藏它。
如果要在當前視圖中隱藏標簽欄,可以執行以下操作:
請注意,UIKit 似乎將標簽欄帶回了應用程序簡歷。 所以你必須訂閱通知UIApplication.didBecomeActiveNotification
並調用上面的函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.