问题描述
在 iOS 5 中,我们可以通过编程方式更改设备方向:
In iOS 5 we could change the device orientation programmatically like so:
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
但在 iOS 6 setOrientation
已弃用,如何在 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 - 使用此代码,当你在视图中显示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中以编程方式更改设备方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!