Possible Duplicate:
UIViewController returns invalid frame?
While debugging i've noticed that in viewDidLoad
call my view frame is origin=(x=0, y=20) size=(width=320, height=460)
which is not accurate. In viewWillAppear
call it is set up correctly: origin=(x=0, y=0) size=(width=320, height=416)
taking into consideration navigation bar height.
My subviews layout depends on root view, but i don't want to set up them each time view will appear.
How should we deal with these two calls?
The proper place to deal with view layout is in the UIViewController viewWillLayoutSubviews
method. This is called whenever the view controller's view is sized such as when first shown and when rotated.
As you have seen, the view controller's view has not been fully sized yet when viewDidLoad
is called.
If you need to support iOS 4.3 then you can't use viewWillLayoutSubviews
since it was added in 5.0. In this case, do the layout in viewWillAppear:
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With