开发者

Force portrait orientation on pushing new view to UINavigationViewController

开发者 https://www.devze.com 2022-12-13 09:49 出处:网络
I have a TabBar bases application, which supports Landscape orientation only for one special view (the rootview of a UINaviagtionController). Now i want to force portrait orientation for all other vie

I have a TabBar bases application, which supports Landscape orientation only for one special view (the rootview of a UINaviagtionController). Now i want to force portrait orientation for all other views for this navigationcontroller. I have tried to use

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];

This works great but this piece of code is a private api call and I can not risk a app rejection.

I have also tried to rotate the next view manually but this rotates only the view and not the na开发者_JAVA技巧vigation or the tab bar.

Is there a similary way to force orientation change?


There is currently no way to do that. Have a look at this question, I have the same problems. With a tabbar application, you must have everything to autorotate, or nothing. You can find ways to have shouldAutorotate answer differently on each view, but actually this does not work. I don't know if this is an intended behaviour or a bug, anyway the only viable solution I'm aware of (without using undocumented API) is to manage the rotation by yourself, and do not rely on autorotation.

This means in other words that you need to start orientation notifications (look at UIDevice, there are methods to start and stop notifications about the device orientation), then for each view you want to rotate register as observer, and manage orientation manually, like this (don't remember where I got this snippet):

// Rotates the view.
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
self.view.transform = transform;
0

精彩评论

暂无评论...
验证码 换一张
取 消