Question

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?

Was it helpful?

Solution

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:.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top