[英]UIView frame when navigation bar and tab bar controller exist
I am creating a UIView programatically in loadView . 我在loadView中以编程方式创建了一个UIView。 The application has a UITabBarController and UINavigationController. 该应用程序有一个UITabBarController和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. UIView有一个处理这种情况的财产。 As you are creating it programatically the code to use is: 在以编程方式创建它时,要使用的代码是:
UIView *aView = [[UIView alloc] init];
aView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.