簡體   English   中英

存在導航欄和標簽欄控制器時的UIView框架

[英]UIView frame when navigation bar and tab bar controller exist

我在loadView中以編程方式創建了一個UIView。 該應用程序有一個UITabBarController和UINavigationController。

當標簽欄和導航欄都存在時,如何創建自動調整大小的視圖?

我目前解決這個問題的方法是計算導航和標簽欄控制器的高度,並從主屏幕的高度中減去它們:

float navObjectsHeight = self.tabBarController.tabBar.frame.size.height 
    + self.navigationController.navigationBar.frame.size.height;

CGRect mainFrame = CGRectMake(0, 0, screenFrame.size.width, 
  screenFrame.size.height - navObjectsHeight);

UIView *contentWrapper = [[UIView alloc] initWithFrame:mainFrame];

UIView有一個處理這種情況的財產。 在以編程方式創建它時,要使用的代碼是:

UIView *aView = [[UIView alloc] init];
aView.autoresizingMask = UIViewAutoresizingFlexibleHeight;

暫無
暫無

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

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