This observation is more than anything else, because I seem to have found a workaround ...
The code below does not work when it is on a controller that has been ported to the UINavigationController stack. In this situation, [UIDevice currentDevice].orientation
successively 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 is made:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
To get around this UIDeviceOrientationUnknown
problem, I now use the following:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if (UIInterfaceOrientationIsLandscape(orientation)) { etc. } else { etc. }
... which works every time.
However, I do not understand why the first option will not work in the context of a push-view controller. Anyone ideas? Is this just a mistake?
user1095226
source share