Observe UIDeviceOrientationDidChangeNotification
:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
...
- (void)orientationDidChange:(NSNotification *)note
{
NSLog(@"new orientation = %d", [[UIDevice currentDevice] orientation]);
}
UIDevice Class Reference
I should note that yo uneed to add -beginGeneratingDeviceOrientationNotifications
when you want these notifications to be sent, and call -endGeneratingDeviceOrientationNotifications
when you want them to stop. There is a battery impact of generating these, so you should only do so when your view is on screen. UIViewController
does all this for you, so if you have a view controller, it is worth letting it do the work.