iOS: Forcing orientation in your view controller (iOS 6 and iOS < 6)
Got this trouble on forcing the app to be in a a landscape mode. Let say, you have a standard orientation of a Portrait but at first force the view controller to be in landscape where the button is located in the left side.
So I have this code that you can try, play, and modify. See below,
or
So I have this code that you can try, play, and modify. See below,
- //
- // MainViewController.h
- @interface MainViewController : UIViewController <UIWebViewDelegate>
- @end
- // MainViewController.m
- #import "MainViewController.h"
- @implementation UINavigationController (autorotation)
- // >= iOS 6
- -(BOOL)shouldAutorotate
- {
- UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation;
- NSLog(@"intefaceorientation: %d", interfaceOrientation);
- [self.topViewController shouldAutorotate];
- return YES;
- }
- // >= iOS 6
- -(NSUInteger)supportedInterfaceOrientations
- {
- return UIInterfaceOrientationMaskLandscapeLeft;
- }
- @end
- @implementation MainViewController
- #pragma mark view did load
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.navigationController.navigationBarHidden = YES;
- }
- - (void)viewDidAppear:(BOOL)animated
- {
- // < iOS 6
- [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
- }
- // < iOS 6
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
- return YES;
- }
- return NO;
- }
- - (void)viewDidUnload {
- [super viewDidUnload];
- }
- @end
Comments
Post a Comment