在iPhone上强制更改UIInterfaceOrientation [英] Forcing UIInterfaceOrientation changes on iPhone

查看:116
本文介绍了在iPhone上强制更改UIInterfaceOrientation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要获得一个iPhone应用程序,它只需要导航控制器堆栈中的每一次推送或弹出来改变方向。

I'm strugging with getting an iPhone application which requires just about every push or pop in the Nav Controller Stack to change orientation.

基本上第一个视图是肖像,第二个景观再次成为第三幅画面(是的,我知道这不太理想,但那是设计,我必须实现它)。

Basically the first view is portrait, the second landscape the third portrait again (Yes I know this is less than ideal, but that's the design and I've got to implement it).

我是在这里通过各种建议....

如何在没有设备自动旋转的情况下检测iPhone上的旋转?

在将新视图推送到UINavigationViewController时强制纵向方向

有一个记录的方式来设置我电话定位?

但没有取得全部成功。

I've been through various advice on here....
How do I detect a rotation on the iPhone without the device autorotating?
Force portrait orientation on pushing new view to UINavigationViewController
Is there a documented way to set the iPhone orientation?
But without total success.

设置链接3.1.2我看到上面链接的文章似乎指示如果我的纵向视图用
推送视图

Setting to link against 3.1.2 my reading of the linked articles above seems to indicate that if my portrait view pushes a view with


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeRight) );
}


那么那个视图应该旋转到横向。它会以破损的肖像形式出现,然后在设备转动时正确旋转。

Then then that view should appear rotated to landscape. What happens is it appears in its "broken" portrait form, then rotates correctly as the device is turned.

如果我将控制器弹回我的纵向视图(其中有一个合适的shouldAutoRotate ...)然后保持在破碎的横向视图中,直到设备返回纵向。

If I pop the controller back to my portrait view (which has an appropriate shouldAutoRotate...) then that remains in broken landscape view until the device is returned to portrait orientation.

我也尝试删除所有的shouldautorotate消息,并且而是通过转换视图来强制旋转。这种工作,我已经想通过移动状态栏(实际上隐藏在我的应用程序中) [UIApplication sharedApplication] .statusBarOrientation = UIInterfaceOrientationLandscapeRight; 键盘在需要时会以正确的方向显示。

I've also tried removing all the shouldautorotate messages, and instead forcing rotation by transforming the view. This kind of works, and I've figured out that by moving the status bar (which is actually hidden in my application) [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight; the keyboard will appear with the correct orientation when desired.

这种方法的问题在于,当您没有状态栏时,状态栏变换很奇怪和丑陋 - a每次更改都会在页面上隐藏阴影。

The problem with this approach is that the status bar transform is weird and ugly when you don't have a status bar - a shadow looms over the page with each change.

所以。我错过了什么

1)我认为在3.1.2(或可能更早)中,应该只能通过推动控制器来提供所需的方向吗?

1) Am I wrong in thinking that in 3.1.2 (or possibly earlier) shouldAutorotateToInterfaceOrientation should provide the desired orientation simply by pushing controllers ?

2)是否有其他方法让键盘以正确的方向显示。

2) Is there another way of getting keyboards to appear in the correct orientation.

3)未记录的API是否可以调用(请不要!)

3) Are the undocumented API calls the way to go (please no!)

推荐答案

你不应该使用 [UIViewController shouldAutorotateToInterfaceOrientation:] 触发方向改变;它只是让系统知道是否允许自动旋转。您仍然应该更新它以指定允许的方向。

You shouldn't use [UIViewController shouldAutorotateToInterfaceOrientation:] to trigger an orientation change; it's only there to let the system know if automatic rotations are allowed. You should still update it to specify the orientation that's allowed though.

如果要在显示特定视图时更改方向,则应调用 [UIApplication setStatusBarOrientation:animated:] 在每个强制特定方向的视图控制器的 [UIViewController viewWillAppear:] 覆盖方法中。当视图被推入堆栈时以及当它被弹出时,这将导致更改。确保在覆盖方法中调用 super

If you want to change the orientation when a particular view is showing, you should call [UIApplication setStatusBarOrientation:animated:] inside your [UIViewController viewWillAppear:] override method for each of the view controllers that force a particular orientation. That will cause a change when a view is being pushed onto the stack and when it's being popped off it. Make sure you call super in your override method.

这也是更改状态栏方式的正确位置显示,如果那是你正在做的事情。

This is also the right place to change how the status bar is displayed, if that's something you're doing.

这篇关于在iPhone上强制更改UIInterfaceOrientation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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