Force portrait orientation when clicking a new view on the UINavigationViewController

I have a basic TabBar application that supports landscape orientation for only one special view (the root view of the UINaviagtionController). Now I want to force portrait orientation for all other views for this navigation controller. I tried to use

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];

This works fine, but this piece of code is a private api call, and I cannot risk the application crashing.

I also tried to rotate the next view manually, but this only rotates the view, not the navigation or tab bar.

Is there a similar way to force an orientation change?

+4
objective-c iphone
Dec 01 '09 at 8:07
source share
1 answer

There is currently no way to do this. Look at this question , I have the same problems. In a tab app, you must have everything to autorotate, or nothing. You can find ways for toAsutorotate to respond differently on each view, but it doesn't actually work. I don’t know if this is the intended behavior or error, in any case the only viable solution that I know of (without using the undocumented API) is to control the rotation myself and do not rely on autorotation.

This means that you need to start orientation notifications (see UIDevice, there are ways to start and stop device orientation notifications), then for each view you want to rotate the register as an observer and control the orientation manually, like this (I don’t remember where I got this snippet):

 // Rotates the view. CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2); self.view.transform = transform; 
+6
Dec 01 '09 at 13:38
source share



All Articles