Reputation: 16051
I want to find out when the status bar rotates. Receiving a screen rotation notification can confuse matters with orientations such as 'face up' and 'face down'. Managing rotation based on the orientation of the status bar is therefore the simplest and cleanest way of doing it. How do i get a notification when the orientation changes?
Upvotes: 6
Views: 4692
Reputation: 318814
You need to register for the UIApplicationDidChangeStatusBarOrientationNotification
notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
- (void)statusBarOrientationChange:(NSNotification *)notification {
UIInterfaceOrientation orient = [notification.userInfo[UIApplicationStatusBarOrientationUserInfoKey] integerValue];
// handle the interface orientation as needed
}
Note that this approach never results in the "face up" or "face down" device orientations since this only deals with interface orientations.
Upvotes: 12
Reputation: 18855
//register to receive orientation notifications somewhere:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:UIDeviceOrientationDidChangeNotification object:nil];
-(void)detectOrientation{
switch ([[UIDevice currentDevice] orientation]) {
case UIDeviceOrientationFaceDown:{
}
break;
default:{
}
break;
}
}
If it's not working, check orientation lock! Wasted hours on that.
Upvotes: -1