在没有XIB文件的情况下,在loadView方法(在UIViewController中)计算视图大小的最佳实践是什么?
这是我的解决方案:
- (void)loadView { //Calculate Screensize BOOL statusBarHidden = [[UIApplication sharedApplication] isstatusBarHidden ]; BOOL navigationBarHidden = [self.navigationController isNavigationBarHidden]; BOOL tabBarHidden = [self.tabBarController.tabBar isHidden]; CGRect frame = [[UIScreen mainScreen] bounds]; if (!statusBarHidden) { frame.size.height -= [[UIApplication sharedApplication] statusBarFrame].size.height; } if (!navigationBarHidden) { frame.size.height -= self.navigationController.navigationBar.frame.size.height; } if (!tabBarHidden) { frame.size.height -= self.tabBarController.tabBar.frame.size.height; } UIView *v = [[UIView alloc] initWithFrame: frame]; [v setBackgroundColor: [UIColor whiteColor] ]; [v setAutoresizingMask: UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ]; [self setView: v ]; [v release]; }
这段代码好吗,还是我应该编辑一些东西?
解决方法
文档建议使用[[UIScreen mainScreen] applicationFrame]获取没有状态栏的屏幕边界
原文地址:https://www.jb51.cc/iOS/332056.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。