How do I programmatically set device orientation in iOS 7? How do I programmatically set device orientation in iOS 7? ios ios

How do I programmatically set device orientation in iOS 7?


For iOS 7 & 8:

Objective-C:

NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

Swift 3+:

let value = UIInterfaceOrientation.landscapeLeft.rawValueUIDevice.current.setValue(value, forKey: "orientation")

I call it in - viewDidAppear:.


Use this. Perfect solution to orientation problem..ios7 and earlier

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


You need to call attemptRotationToDeviceOrientation (UIViewController) to make the system call your supportedInterfaceOrientations when the condition has changed.