Subview Doesnt AutoSize When Added to Root View Controller
Posted
by Per
on Stack Overflow
See other posts from Stack Overflow
or by Per
Published on 2010-04-07T12:40:08Z
Indexed on
2010/04/07
12:43 UTC
Read the original article
Hit count: 460
Hello,
I have a root view controller that will have up to 10 or so subviews. I am implementing autorotation/autosize accross the entire app.
My problem is this: - When I allocate all the view controllers and add each as a subview to the root controller during startup, everything works as it should. The only problem is that each view controller needs time to initialize. This causes my application to load very slowly.
Instead I am trying to allocate the view controllers as they are required. Now I find that if the application goes into Landscape, and I allocate a view controller that is designed in portrait, it will autorotate but the autosize doesnt happen.
In other words as soon as the subview is added to the root controller in portrait mode it rotates and sizes correctly (and stays that way). If the subview is added when the root controller is in landscape it rotates but doesnt autosize (and view sizes remain messed up rotating back to portrait)
I have tried to force an autosize by calling SetNeedsLayout, SetNeedsDisplay, and LayoutIfNeeded but nothing works. I know i could probably do this manually by determining the root controllers orientation and resizing the subviews appropriately, but this is a lot of work for something that should work automatically.
Am I missing something? Any help would be appreciated. My project is an iPad port from an iPhone app, the iPhone app doesnt rotate so Im not sure if this may be something wrong with the 3.2 beta.
© Stack Overflow or respective owner