将新视图推送到UINavigationViewController时强制纵向方向 [英] Force portrait orientation on pushing new view to UINavigationViewController

查看:76
本文介绍了将新视图推送到UINavigationViewController时强制纵向方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TabBar基础应用程序,它仅支持一个特殊视图(UINaviagtionController的根视图)的Landscape方向。现在我想为此导航控制器强制所有其他视图的纵向方向。
我试图使用

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];

这很好但是这段代码是私人api电话,我不能冒被拒绝的风险。

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

I还试图手动旋转下一个视图但这只旋转视图而不是导航或标签栏。

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

是否有类似的方法强制方向改变?

Is there a similary way to force orientation change?

推荐答案

目前无法做到这一点。
看看这个问题,我遇到了同样的问题。使用tabbar应用程序,您必须拥有自动旋转的所有内容,或者没有任何内容。您可以找到让shouldAutorotate在每个视图上以不同方式回答的方法,但实际上这不起作用。我不知道这是一个预期的行为还是一个bug,无论如何,我所知道的唯一可行的解​​决方案(不使用未记录的API)是自己管理轮换,而不是依赖自动旋转。

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.

这意味着换句话说你需要开始方向通知(查看UIDevice,有方法可以启动和停止有关设备方向的通知),然后对于你想要旋转的每个视图注册为观察者,并像这样手动管理方向(不记得我在哪里得到这个片段):

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;

这篇关于将新视图推送到UINavigationViewController时强制纵向方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆