Skip to content

Instantly share code, notes, and snippets.

@macguru
Created May 28, 2014 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macguru/17ee7d47acbb4d4a2258 to your computer and use it in GitHub Desktop.
Save macguru/17ee7d47acbb4d4a2258 to your computer and use it in GitHub Desktop.
Enforce device rotation by using a temporary window and view controller.
@interface FixedViewController : UIViewController
@property(nonatomic) NSUInteger supportedInterfaceOrientations;
@end
@implementation FixedViewController
@end
...
- (void)rotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
UIWindow *window = [[UIWindow alloc] initWithFrame: UIScreen.mainScreen.bounds];
[window makeKeyAndVisible];
FixedViewController *vc = [FixedViewController new];
vc.supportedInterfaceOrientations = 1 << orientation;
window.rootViewController = vc;
window.hidden = YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment