1

I have this code and it works perfectly on iOS 5 but not on iOS 6 please help

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
    {
        return (orientation != UIDeviceOrientationPortrait) &&
        (orientation != UIDeviceOrientationPortraitUpsideDown);
    }
OnkaPlonka
  • 1,232
  • 10
  • 19
  • 1
    Have you looked at the docs for `UIViewController`? It has a whole section talking about the changes made for supporting rotations. There are also many existing questions on this exact topic. Please do some searching. – rmaddy Dec 16 '12 at 09:24
  • See http://stackoverflow.com/questions/12780925/handling-rotation-in-ios6 – rmaddy Dec 16 '12 at 09:27

2 Answers2

2

let try this : First inside viewDidLoad function use this code :

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}

then, i'm create function that will receive notification for two lines of code :

- (void)orientationChanged:(NSNotification *)object{
    NSLog(@"orientation change");
    UIDeviceOrientation deviceOrientation = [[object object] orientation];
    if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation == UIInterfaceOrientationPortraitUpsideDown){
        if(deviceOrientation ==UIInterfaceOrientationPortrait){
            NSLog(@"Changed Orientation To Portrait");
            // Handle your view.
        }
    }else{
        if(deviceOrientation ==UIInterfaceOrientationLandscapeLeft){
            NSLog(@"Changed Orientation To Landscape left");
            // Handle your view.
        }else{
            NSLog(@"Changed Orientation To Landscape right");
            // Handle your view.
        }

    }
}

i hope my answer will help. Cheers.

IKQ
  • 490
  • 3
  • 11
1

In iOS6, "shouldAutorotateToInterfaceOrientation" method is deprecated.Try setting orientation in plist file.

Paramasivan Samuttiram
  • 3,728
  • 1
  • 24
  • 28
  • I added the needed orienation in plist file, please try the other method here also.http://stackoverflow.com/questions/12577879/shouldautorotatetointerfaceorientation-is-not-working-in-ios-6 – Paramasivan Samuttiram Dec 16 '12 at 09:29