Reputation: 382
I'm working on an application (Xcode 4.5 iOS 6), it must be compatible for the devices that have installed software version, starting at 4.5 and default iPhone 5.
I know that the new iOS 6 changes came with the auto-rotate mode.
When you turn on your device "iPhone Simulator 6.0" application behaves normally but when I run the "iPhone Simulator 5.0" problems in the way of rotation.
I put in the code, along with new ways to rotate from iOS 6 and the old method (deprecated) to iOS 5.
So look for the rotate methods:
#pragma mark - Rotate Methods
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (BOOL) shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
#pragma mark - Rotate Methods iOS 5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
[menuPortrait setHidden:NO];
[menuLandscape setHidden:YES];
}
if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
[menuPortrait setHidden:YES];
[menuLandscape setHidden:NO];
}
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation))
{
[self.menuLandscape setHidden:YES];
[self.menuPortrait setHidden:NO];
}
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
{
[self.menuLandscape setHidden:NO];
[self.menuPortrait setHidden:YES];
}
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
Can you help me with some advice regarding this issue! Thanks in advance for your answers!
Upvotes: 4
Views: 3292
Reputation: 13414
I achieved it by subclassing all view controller like this:
//.h #import
@interface ITViewController : UIViewController
@end
//.m
#import "ITViewController.h"
@interface ITViewController ()
@end
@implementation ITViewController
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
This force landscape orientation mode. You can update the content of both methods to comply to your desired behavior
Upvotes: 3