Ok guys, I will post my decision.
What I have:
- A view-based application with multiple view controllers. (It was navigation, but I had to do it based on a review due to orientation problems).
- All view controllers are a portrait, except for one - landscapeLeft.
Tasks:
- One of my view controllers should automatically rotate to landscape, regardless of how the user holds the device. All other controllers must be portraits, and after exiting the landscape controller, the application must be forced to rotate to the portrait, no matter again how the user holds the device.
- This should work on both iOS 6.x and iOS 5.x
Go!
( Refresh Removed macros suggested by @Ivan Vučica)
In all of your PORTRAIT view controllers, override autorotation methods as follows:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return (toInterfaceOrientation == UIInterfaceOrientationPortrait); } -(BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }
You can see two approaches: one for iOS 5 and the other for iOS 6.
The same goes for your LANDSCAPE view controller with some additions and changes:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ [image_signature setImage:[self resizeImage:image_signature.image]]; return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft); } -(BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { [image_signature setImage:[self resizeImage:image_signature.image]]; return UIInterfaceOrientationMaskLandscapeLeft; }
ATTENTION : to force autorotation in iOS 5 , you must add this:
- (void)viewDidLoad{ [super viewDidLoad]; if ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0) [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO]; }
Similarly, after you leave the LANDSCAPE controller, no matter which controller you download, you must enable autorotation again for iOS 5, but now you will use the UIDeviceOrientationPortrait when you go to the PORTRAIT controller:
- (void)viewDidLoad{ [super viewDidLoad]; if ([[[UIDevice currentDevice] systemVersion] floatValue] < 6.0) [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO]; }
Now the last one (and this is a bit strange) - you have to change the way you switch from controller to another, depending on iOS:
Make the NSObject class "Schalter" ("Switch" in German).
In Schalter.h they say:
At Schalter.m they say:
#import "Schalter.h" #import "AppDelegate.h" @implementation Schalter + (void)loadController:(UIViewController*)VControllerToLoad andRelease:(UIViewController*)VControllerToRelease{
NOW, this is how you use Schalter (assuming you're moving from a Warehouse controller to a Products controller):
Of course you must free the instance_to_products object:
- (void)dealloc{ [instance_to_products release]; [super dealloc]; }
OK it's all over Now. Feel free to subvert, I don't care. This is for those who are looking for solutions, not for reputation. Hurrah! Sava Mazare.