如果这是重复,请原谅我.我认为这肯定是个明显的问题.
我在故事板中有一个容器,它是ModelViewController类(整个视图控制器).从ModelViewController我需要获取容器的宽度和高度.我目前正在尝试:
self.view.bounds.size
产生0.563380和0.000000.我也试过了
self.view.frame.size
这产生了整个屏幕的尺寸.我在这里错过了什么?
解决方法
从
this post起
View frames are not actually useable in viewDidLoad; you should move all of your geometry-manipulating code into viewWillAppear. The system will clobber any changes you set in viewDidLoad between there and when it’s about tom come on screen.
Actually,you should move geometry changes to -viewDidAppear pre-iOS 5 and to -viewWillLayoutSubviews for iOS 5+. -viewWillAppear: may not actually have the correct bounds/orientation if the view is being animated.
我找到了解决方案.从viewWillLayoutSubviews调用时确实给出了正确的尺寸.我从viewDidLoad调用给出了不正确的结果.