Phương pháp hay nhất để tính kích thước khung trong phương thức loadView
(trong UIViewController
) không có tệp XIB?Cách thực hành tốt nhất để tính kích thước khung trong phương thức loadView
Đây là giải pháp của tôi:
- (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];
}
là mã này sao, hay tôi nên sửa cái gì?
thx, đây là tài liệu dành cho bất kỳ ai quan tâm: https://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIScreen_Class/Reference/UIScreen.html#//apple_ref/occ/instp/UIScreen/applicationFrame – CarlJ
[i can] (https://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UIScreen_Class/Reference/UIScreen.html) – wattson12
Bạn căn cứ vào khiếu nại này như thế nào? Bạn đã có một tài liệu tham khảo? – lhunath