我现在面临一个非常奇怪的问题.获取[[self view] bounds] .size.width总是320它根据设备没有改变. iPhone 5,6& 6加上所有的方法返回320.000000.
- (void)viewDidLoad { [super viewDidLoad]; NSLog(@"%f",[[self view] bounds].size.width); } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; NSLog(@"%f",[[self view] bounds].size.width); } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; NSLog(@"%f",[[self view] bounds].size.width); }
产量
2015-02-11 14:48:03.274 MyApp[2948:86285] 320.000000 2015-02-11 14:48:03.274 MyApp[2948:86285] 320.000000 2015-02-11 14:48:03.783 MyApp[2948:86285] 320.000000
即使是启动画面也在那里.
如何获得视图的实际大小?
解决方法
使用
NSLog(@"%f",[[UIScreen mainScreen] bounds].size.width);
代替
NSLog(@"%f",[[self view] bounds].size.width);
它给你预期的w / h.