Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
282 views
in Technique[技术] by (71.8m points)

objective c - How to change the device orientation programmatically in iOS 6

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

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

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

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

This doesnt generate "leak" warning as performSelector will.

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...