[UIDevice currentDevice].orientation == UIDeviceOrientationUnknown following UINavigationController push

Это скорее наблюдение, чем что-либо еще, потому что я, кажется, нашел обходной путь...

Код ниже не работает когда он находится в контроллере, который был вытолкнут в стек UINavigationController. В этой ситуации [UIDevice currentDevice].orientation последовательно возвращает UIDeviceOrientationUnknown.

-(void)layoutAccordingToOrientation {
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
    NSLog(@"layoutAccordingToOrientation/orientation==%i", orientation);
    if (UIInterfaceOrientationIsLandscape(orientation)) {
        :
        _detailToolbar.frame = CGRectMake(0, 660, 1024, 44);
    } else {
        :
        _detailToolbar.frame = CGRectMake(0, 916, 768, 44);
    }
}

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [self layoutAccordingToOrientation];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

Следующий вызов был сделан:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

Чтобы обойти эту UIDeviceOrientationUnknown-проблему, я теперь использую следующее:

UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
    etc.
} else {
    etc.
}

... что работает каждый раз.

Тем не менее, я не понимаю, почему первый вариант не работает в контексте контроллера представления с толчком. Есть идеи? Может, это просто ошибка?

7
задан user1095226 13 December 2011 в 08:04
поделиться