Status bar rotation notification

ios, iphone, objective-c, uistatusbar, uiview

Solution

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.

Problem

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?

Original source