This is an observation more than anything, because I appear to have found a work-around...
The code below fails to work when it's in a controller which has been pushed onto a UINavigationController stack. In this situation [UIDevice currentDevice].orientation
consistently returns 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;
}
The following call has been made:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
To work around this UIDeviceOrientationUnknown
-problem, I now use the following instead:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
etc.
} else {
etc.
}
... which works every time.
Still, I fail to see why the first variation would not work in the context of a pushed view controller. Ideas anyone? Is it simply a bug?