問題描述
我有一個 UIViewController 子類,它的視圖在 NIB 文件中配置.該視圖有一個 UIScrollView 子視圖.
I have a UIViewController subclass whose view is configured in a NIB file. The view has a UIScrollView subview.
UIScrollView 幾乎占據了它的整個 NIB 文件,但它的超級視圖作為子視圖添加到一個小得多的視圖(配置在不同的 NIB 中)——例如UIScrollView 是它自己的 NIB 高度的 80%,但最終只有應用程序窗口高度的 10%.
The UIScrollView takes up almost its entire NIB file but it's superview is added as a subview to a much smaller view (configured in a different NIB) - e.g. the UIScrollView is 80% the height of it's own NIB but ends up only being 10% the height of the application's window.
當我在 viewController 的 viewDidLoad 方法中調用 [scrollView bounds].size.height 時,我得到了 scrollView 相對于它自己的 NIB 的高度,而不是它最終調整為由其超級視圖指定的高度(例如 80窗口高度的 % 而不是 10%).
When I call [scrollView bounds].size.height in the viewController's viewDidLoad method, I get the height of the scrollView relative to it's own NIB, rather than the height it ends up resizing to as dictated by its superviews (e.g. 80% of the window's height rather than 10%).
如果我稍后調用 [scrollView bounds].size.height(例如處理旋轉事件),我會得到正確的值.
If I call [scrollView bounds].size.height later on (e.g. to handle a rotation event), I get the correct value.
最初我如何才能獲得正確調整大小的值?
How can I get the correctly re-sized value initially?
推薦答案
你試過用 viewWillAppear:
或 viewDidAppear
處理嗎?
Have you tried dealing with it in viewWillAppear:
or viewDidAppear
?
這篇關于UIScrollView 邊界尚未在“viewDidLoad"中調整大小.的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!