Autorotation has changed in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation:
method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientations:
and shouldAutorotate
methods:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Modal ViewControllers no longer get rotation calls in iOS 6: The willRotateToInterfaceOrientation:duration:, willAnimateRotationToInterfaceOrientation:duration:
, and didRotateFromInterfaceOrientation:
methods are no longer called on any view controller that makes a full-screen presentation over itself—for example those that are called with: presentViewController:animated:completion:
.
This answer will further explain the rotation changes in iOS 6
[EDIT]
Completely different way is to register for rotation events. The advantage is that all objects can register for this, not only UIViewController
. This is usually done when the view loads and stopped when the view disappears (put in dealloc here). The method in the selector is called when orientation changes (here it is orientationChanged:
):
- (void)viewDidLoad {
[super viewDidLoad];
// Start generating device rotations and register for them
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
- (void)dealloc {
// Deregister and stop generating device rotations
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[super dealloc];
}