是否有记录的方法来设置 iPhone 方向? [英] Is there a documented way to set the iPhone orientation?

查看:26
本文介绍了是否有记录的方法来设置 iPhone 方向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我想在某些视图中支持设备旋转,但其他视图在横向模式下没有特别意义,因此当我交换视图时,我想强制将旋转设置为纵向.

I have an app where I would like to support device rotation in certain views but other don't particularly make sense in Landscape mode, so as I swapping the views out I would like to force the rotation to be set to portrait.

UIDevice 上有一个未公开的属性设置器,它可以执行此操作,但显然会生成编译器警告,并且可能会随着 SDK 的未来版本而消失.

There is an undocumented property setter on UIDevice that does the trick but obviously generates a compiler warning and could disappear with a future revision of the SDK.

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

是否有任何记录在案的方法来强制定向?

Are there any documented ways to force the orientation?

更新:我想我会提供一个例子,因为我不是在寻找 shouldAutorotateToInterfaceOrientation,因为我已经实现了它.

Update: I thought I would provide an example as I am not looking for shouldAutorotateToInterfaceOrientation as I have already implemented that.

我希望我的应用程序在视图 1 中支持横向和纵向,但在视图 2 中仅支持纵向.我已经为所有视图实现了 shouldAutorotateToInterfaceOrientation 但如果用户在视图 1 中处于横向模式然后切换到视图 2,我想要强制手机旋转回纵向.

I want my app to support landscape and portrait in View 1 but only portrait in View 2. I have already implemented shouldAutorotateToInterfaceOrientation for all views but if the user is in landscape mode in View 1 and then switches to View 2, I want to force the phone to rotate back to Portrait.

推荐答案

这在以后的 iPhone 3.1.2 SDK 上不再是问题.它现在似乎尊重被推回堆栈的视图的请求方向.这可能意味着您需要检测较旧的 iPhone 操作系统版本,并且仅在最新版本之前应用 setOrientation.

This is no longer an issue on the later iPhone 3.1.2 SDK. It now appears to honor the requested orientation of the view being pushed back onto the stack. That likely means that you would need to detect older iPhone OS versions and only apply the setOrientation when it is prior to the latest release.

目前尚不清楚 Apple 的静态分析是否会理解您正在解决旧的 SDK 限制.Apple 个人已告知我在我的下一次更新时删除方法调用,因此我不确定对旧设备的破解是否能通过审批流程.

It is not clear if Apple's static analysis will understand that you are working around the older SDK limitations. I personally have been told by Apple to remove the method call on my next update so I am not yet sure if having a hack for older devices will get through the approval process.

这篇关于是否有记录的方法来设置 iPhone 方向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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