6

since iOS6 i have big problems with the rotation. I implemented all the new rotation methods (shouldAutorotate, preferredInterfaceOrientationForPresentation, supportedInterfaceOrientation), but all views are still rotating. The funny thing is that the views are keeping their sizes and the rest of the Window (in Landscape) is black.

Thats the way i implement it, is there anything wrong?

#pragma mark -
#pragma mark - InterfaceOrientation iOS 5 
//Deprecated in iOS 6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -
#pragma mark - InterfaceOrientation iOS 6

- (BOOL)shouldAutorotate{
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortraitUpsideDown;
}

Thanks for your help folks.

3
  • Shouldn't that last one be UIInterfaceOrientationMaskPortrait? Oct 8, 2012 at 7:56
  • Its ok if it rotates to both portrait orientations, but it should not rotate to landscape orientation
    – Fry
    Oct 8, 2012 at 8:13
  • 2
    Just try to change the app's default orientation support ie in the plist file under the key Supported interface orientation select only two supported interface. This will solve your problem :)
    – The iOSDev
    Oct 8, 2012 at 8:32

4 Answers 4

9

I solved the Problem by making a category for the navigationcontroller:

@implementation UINavigationController (iOS6fix)

-(BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations
{
    return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

@end

Thanks to everyone for the answers!

1
  • I had to create a subclass of UINavigationController and used object_setClass(.., ..) to set my navigationController to that class. I also implemented those 3 methods. Best you mark your answer as the the accepted answer so people can see coz there seems to be a lot of confusion and problems coming up as a result of this change
    – pnizzle
    Oct 10, 2012 at 2:00
0

I had that too, it rotate even if I turnes it to NO.

Two options:

  1. go to your Project settings and change the possible orientations

  2. Remove all the methods for AUTOROTATE. Even if they are set to NO, they rotate for me.

0

I used the following category on UIViewController to have landscape only on iOS5 and 6. Maybe it helps someone.

#import <UIKit/UIKit.h>

@implementation UIViewController (iOS6fix)

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

@end
-1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    //Make sure your window to assgin the view controller object to rootViewController, Please don't add controller view as a sub view on window.
    self.window.rootViewController = viewController;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.