ios – 从视图中获取容器的宽度和高度

前端之家收集整理的这篇文章主要介绍了ios – 从视图中获取容器的宽度和高度前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果这是重复,请原谅我.我认为这肯定是个明显的问题.

我在故事板中有一个容器,它是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调用给出了不正确的结果.

猜你在找的Xcode相关文章