Question

In my objects init method

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(didRotate:)
                                                    name:@"UIDeviceOrientationDidChangeNotification" 
                                                  object:nil];

did Rotate Method

- (void) didRotate:(NSNotification *)notification {

    NSLog(@"rotate notification");

    //MA_MobileAppDelegate *appDelegate = (MA_MobileAppDelegate *)[[UIApplication sharedApplication] delegate];

    //UIInterfaceOrientation orientation = appDelegate.tabBarController.interfaceOrientation;
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

For some reason the didRotate seems to be called before the actual rotation. Thus when I try to get the current/final rotation I get the last one. There is only 1 view controller that this doesn't seem to be the case. Any ideas what I'm doing wrong?

Was it helpful?

Solution

I had to delay my code

[self performBlock:^(id sender) {

//rotation code

} afterDelay:0.1f];

The short delay is all that was needed to give UIApplication the time to update the statusbar orientation property :(

OTHER TIPS

iOS tracks two separate orientations: the device orientation ([[UIDevice currentDevice] orientation]) and the interface orientation ([[UIApplication sharedApplication] statusBarOrientation]). A change to the device orientation may trigger a change to the interface orientation. You're receiving the device-orientation-change notification before the system has changed the interface orientation.

Try observing UIApplicationDidChangeStatusBarOrientationNotification. It's posted by [UIApplication sharedApplication].

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top