0
votes

Currently, here's what's happening. If I'm in portrait mode, and I present a new modalViewController, and then rotate to landscape, autoResizing works perfectly and everything looks great. However, if I'm in landscape, and I present a new modalViewController, autoResizing does not work and everything looks funky. Can anyone think of any possible ideas as to why this could be happening? I'm desperate I've tried everything.

Maybe a way to fix this would be to figure out what code gets called by the system when I'm in portrait and I go landscape. Maybe I can call that exact code if my modalView is presented in landscape. I've tried layoutIfNeeded and setNeedsDisplay but they don't do anything. I've also tried setting the contentMode to redraw-doesn't help.

I have this in my viewDidLoad for the modal view

if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation))
{
    NSLog(@"is landscape, width:%f", self.view.frame.size.width);
}

and this outputs 320, even though I'm in landscape, when it should be 480.

1
More of a conceptual question..I don't know what code I can post that would really be helpful.. - Snowman
Then a conceptual answer you shall have. - CodaFi
The bottom line question comes down to: why does autoResizing work when a modal view is loaded in portrait then rotated to landscape, but not when the modal view is loaded in landscape? - Snowman
Screenshots would be helpful. What does "funky" mean? - ThomasW
Not exactly funky, just not as they should be. The buttons still think they are in portrait mode, and the view layer shadow still thinks it's width is 320. This doesn't happen when I manually rotate to landscape though, this only happens when the view is loaded while in landscape.. - Snowman

1 Answers

2
votes

UIViewAutoResizingMasks are what we refer to as 'struts' and 'springs'. Consider this: you have a large square with a small square inside. In order for that square to stay perfectly centered, you must set a fixed width from each inside edge of the large square, so as to constrain it. These are struts.

Springs, on the other hand, work more like a UIView does during rotation. Let's say our view must stay on the bottom of the screen, aligned in the center. We want to keep it's Top spring flexible so that when the view rotates from 460 px to 320 px, it keeps it's same position relative to the screen's now changed dimensions.

Keeping this in mind, when a view is loaded in portrait (as all UIViewControllers are), but the actual orientation is landscape, it's possible that the view will get 'confused' and maintain a sort of messy hybrid orientation type view. If you absolutely must (and I cannot stress how last resort-ish this is) force an orientation change beforehand, use iOS 5.x's +attemptRotationToDeviceOrientarion