0
votes

I'm having some lay-outing issues, when I start my app in portrait mode and then turn it to landscape mode, views opened after that are returning a wrong value for the rotation.

For instance, I open a view in landscape mode after it was rotated from portrait mode, when I log the rotation it still returns portrait mode:

NSLog(@"%u", [[UIDevice currentDevice] orientation]); // 4
NSLog(@"%f / %f", self.view.frame.size.width, self.view.frame.size.height); // 748.000000 / 1024.000000

When I rotate the iPad to portrait mode and back to landscape mode it returns the right sizes

NSLog(@"%u", [[UIDevice currentDevice] orientation]); // 1
NSLog(@"%f / %f", self.view.frame.size.width, self.view.frame.size.height); // 1024.000000 / 704.000000

Is there anything I need to do to make a newly added view adapt to the rotation?

3
For now I solved it with keeping track of the device width and height in my main view, probably not the best solution, but it works.woutr_be

3 Answers

3
votes

Set the new frame of your views in the viewWillAppear Method. This will set all the items to the correct size, and if you are using a navigation controller this will work when pushing and popping views.

0
votes

This is because your view is loded as portrait mode for first time. So you have to check and rotate the view manually in viewDidLoad.

if (UIInterfaceOrientationIsLandscape(orientation)) 
{

    [self.view setFrame:VIEW_LANDSCAPE_FRAME];

    //do more stuff

}
0
votes

Try as in this link. It worked for me. It would be better to do as in the link in the willAppear than in the viewDidLoad. Also make sure that you've returned your desired orientation in the shouldAutorotateToInterfaceOrientation method and set the right key UIInterfaceOrientation in the info.plist.