Reputation: 61
I am developing a iPad application which always shows in Landscape mode. in iOS5, I was using 'shouldAutorotateToInterfaceOrientation' to return the value as 'YES' and I also configured the info.plist to support only the landscape mode. All goes well.
In iOS 6, I am aware that the method 'shouldAutorotateToInterfaceOrientation' is deprecated. I went thru lot of discussions in the net and tried all suggested solutions but the results are still zero (Meaning, iOS6 simulator shows in portrait mode.
My code is given below…. Any advise is very much appreciated…
In the AppDelicate.m
MyTestUI *myTest = [[MyTestUI alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:myTest];
[navigationController setNavigationBarHidden:YES];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
[myTest release];
return YES;
in the MyTestUI.m
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait) {
}
return YES;
}
**// iOS 5.1 Fix is below**
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
Upvotes: 2
Views: 87
Reputation: 11724
Ok, orientation since iOS 6 is handled from top to bottom :
supported orientation in the summary in XCode : if ALL your screens support the same orientation, then just use this one as it is the simplest.
If you handle different orientation rules depending on the screen of your application, then you want to use shouldAutorotate
and supportedInterfaceOrientation
methods for each UIViewController
. (but do note that UINavigationController
orientation doesn't depend on its top viewController - as opposed to what you might expect, so you could have to subclass UINavigationController
to handle that correctly :
In MytestUI
:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
and in your UINavigationController
subclass
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
Upvotes: 0
Reputation: 5936
If you want your app to always be in landscape simply select landscape in the summary in xcode.
Your app is now locked to landscape
Upvotes: 0
Reputation: 14128
In AppDelegate.m
Instead of
[self.window addSubview:navigationController.view];
use this one:
[self.window setRootViewController:navigationController];
Hope this helps.
Upvotes: 1