Status Bar Notification

I want to know when the status bar rotates. Getting notified of screen rotation can confuse issues with orientations such as face up and face down. Thus, rotation control based on the orientation of the status bar is the simplest and cleanest way to execute it. How to get notification when orientation changes?

+4
source share
2 answers

You need to register to notify UIApplicationDidChangeStatusBarOrientationNotification .

 [[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 leads to face-up or face-down device orientations, as this only applies to the orientation of the interface.

+8
source
 //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 does not work, check the orientation fixation! Spent hours on this.

-1
source

All Articles