简体   繁体   中英

UIView frame when navigation bar and tab bar controller exist

I am creating a UIView programatically in loadView . The application has a UITabBarController and UINavigationController.

How do I create a view that automatically resizes when a tab bar and a navigation bar both exist?

My current approach to this problem is calculating the heights of the navigation and tab bar controllers and subtracting them from the mainScreen's height:

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];

The UIView has a property to handle that situation. As you are creating it programatically the code to use is:

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

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