7

Anyone who's trying the newest iOS 6 beta(version 2 or 3) has the same experience of auto rotation not working?

I am not using storyboard but pure navigation control:

self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:navController.view];

And have:

- (BOOL)shouldAutorotateToInterfaceOrientation: ](UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
    return YES;
}
}

- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown;
}

BUT IOS has no espouse at all, works fine with all previous iOS on 3GS/4S and 4.3,5.0.5.1 simulator, but iOS 6 seems just buggy

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
phil88530
  • 1,499
  • 3
  • 19
  • 27

3 Answers3

10

Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientations and shouldAutorotate methods.

Read more here.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
John Smith
  • 2,012
  • 1
  • 21
  • 33
  • When is the shouldAutorotate function called? It never seems to be called for me when I rotate the screen... Or maybe this is a problem with the simulator? – shim Oct 26 '12 at 04:57
  • Check out my question here http://stackoverflow.com/questions/12640870/ios-6-force-device-orientation-to-landscape – John Smith Oct 27 '12 at 15:12
7

instead of [self.window addSubview:navController.view];

insert self.window.rootViewController = navController;

Medhi
  • 2,656
  • 23
  • 16
  • To increase the quality of your post please include how/why your answer will solve the problem. – Mick MacCallum Oct 03 '12 at 00:29
  • 1
    You just saved my life. I tried everything else for the past 3 hours. I've been getting the callbacks, but iOS ignored everything I put there. Thank you thank you thank you! – gilm Oct 05 '12 at 11:00
  • This works when compiled on iOS6 sdk on iOS, but it does not work for me when compiled on iOS6 sdk ran on iOS5 os! Did you try and look how it works on iOS5? – Koen Oct 24 '12 at 12:29
  • For iOS 5 it's ok also – Medhi Feb 24 '14 at 14:17
  • @0x7fffffff : if you addsubview the controller.view in iOS6+, the rotation delegates won't pass. it's cleaner to set the rootviewcontroller of the window anyway – Medhi Feb 24 '14 at 14:19
  • @Medhi Don't tell me, those are good details to add to your answer. – Mick MacCallum Feb 24 '14 at 14:20
0

The solution is that: Since my app is trying to support from 4.3+, I have to use the navigation controller to do every view switch.

by ios6 seems delegates to the navigation controller, I have to define my own navigation controller, and setup conditions and functions to change its rotation behaviour.

When I load a view, I then do([self.navigationCOntroller setEnableLandscape:(BOOL)false]). in that way you have full controller of your navigation controller.

NOTE: I did try override the navigation controller methods, but seems just get ignored. (This only happens to ios 6.0 as well), haven't test 6.1 yet, so not sure if it's get fixed(which please let me know if it does)

phil88530
  • 1,499
  • 3
  • 19
  • 27