有记录的方式设置iPhone方向吗? [英] Is there a documented way to set the iPhone orientation?

查看:110
本文介绍了有记录的方式设置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.

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

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.

不清楚苹果的静态分析将理解你正在解决老的SDK限制。我个人已经告诉苹果删除方法调用我的下一次更新,所以我还不能确定是否有一个黑客老设备将通过批准过程。

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天全站免登陆