#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
//一旦重写 loadView 方法 则 sb 中关于 view 的设置都失效
-(void)loadView
{
NSLog(@"%s", __FUNCTION__);
self.view = [[UIView alloc]initWithFrame:CGRectMake(20, 30, 40, 50)];
}
//viewDidLoad 是在 init 方法之后调用
//所以在 viewDidload 方法中拿到的 view 的大小可能不准确
//使用 self.view.bounds 来做子视图的布局,可能会不准确,如果不准确 需要在 viewWillAppear 方法中设置
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"%s", __FUNCTION__);
NSLog(@"self.view->frame = %@",NSStringFromCGRect(self.view.frame));
}
//viewWillAppear 方法在 window makeKeyAndVisible 方法调用后才执行 会对 view 进行调整
-(void)viewWillAppear:(BOOL)animated
{
NSLog(@"%s", __FUNCTION__);
[super viewWillAppear:animated];
NSLog(@"self.view->frame = %@",NSStringFromCGRect(self.view.frame));
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
log
[4152:101623] -[ViewController loadView]
[4152:101623] -[ViewController viewDidLoad]
[4152:101623] self.view->frame = {{20, 30}, {40, 50}}
[4152:101623] -[ViewController viewWillAppear:]
[4152:101623] self.view->frame = {{0, 0}, {375, 667}}
网友评论