如何在 iOS 6 中以编程方式更改设备方向 [英] How to change the device orientation programmatically in iOS 6

查看:34
本文介绍了如何在 iOS 6 中以编程方式更改设备方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 5 中,我们可以像这样以编程方式更改设备方向:

In iOS 5 we could change the device orientation programmatically like so:

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

但是在 iOS 6setOrientation 已被弃用,我如何在 iOS 6 中以编程方式更改设备方向?

But in iOS 6 setOrientation is deprecated, how may i change the device orientation programmatically in iOS 6?

推荐答案

这是我的五美分",在 iOS7 和 ARC 上测试

Here are my "five cents", tested on iOS7 with ARC

[[UIDevice currentDevice] setValue:
                      [NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
                            forKey:@"orientation"];

这不会像 performSelector 那样产生泄漏"警告.

This doesnt generate "leak" warning as performSelector will.

UIAlertView - 使用此代码,当您在视图(will/Did)出现期间打开 UIAlertView 时,您会注意到除此视图之外的所有视图都是纵向的(苹果,真的吗?)我无法强制视图重新定向,但发现如果在打开 UIAlertView 之前稍微延迟,则视图有时间改变方向.

UIAlertView - with this code, when you open UIAlertView during view(will/Did)appear you will notice that all but this view is in portrait (apple, really?) I wasn't able to force the view to reorient but found that if you put slight delay before opening the UIAlertView then view has time to change orientation.

注意我将在 2014 年 9 月 12 日开始发布我的应用周,如果它通过或失败,我会更新帖子.

Note I'm releasing my app week commencing 12/09/2014 and I will update post if it will pass or fail.

这篇关于如何在 iOS 6 中以编程方式更改设备方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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