簡體   English   中英

方向更改時隱藏UITabBar

[英]Hide an UITabBar when Orientation change

我有一個非常簡單的問題,但答案並不那么容易。

當我的方向改變時,我想要隱藏UITabBar。

我看了兩種方式:

框架方式

myAppDelegate.tabBarController.tabBar.frame = CGRectMake(<<bottomOfScreen>>);

工作正常,但我有一個空白區域,所以嘗試使用tabBarController.view.frame和myViewController.view.frame但我沒有得到任何好結果。

導航控制器方式

myOtherVC.hideTabBarWhenPushed = YES;
[self.navigationController pushViewController:myOtherVC animated:NO];

工作,但不是我的應用程序的好解決方案

更新:

[appDelegate.tabBarController.view removeFromSuperview];
[self.view removeFromSuperview]; [appDelegate.window addSubview:self.view];
self.view.frame = CGRectMake(0,0,480,320);

工作正常,但不再自動旋轉(當然,我沒有更改shouldAutorotate,它總是返回YES)


如何隱藏我的tabBar並使當前視圖占據其空間?


謝謝

您可以結合使用當前解決方案:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

檢測旋轉。 (我認為你將它與view.transform = CGAffineTransformMakeRotation結合使其旋轉......?)

我認為你可以輕松做到這兩點的方法是:

  1. 將對象重新加載回tabBar控制器 - 將hidesBottomBarWhenPushed設置為YES,以便隱藏viewControllers。
  2. 另一種選擇是在旋轉手機時讓你的視圖成為窗口的唯一視圖,然后在手機旋轉回來時將tabBarController.view放回窗口

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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