这比什么都重要,因为我似乎找到了解决方法......
下面的代码在被推送到 UINavigationController stack 的控制器中时无法工作。在这种情况下[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.
}
...每次都有效。
尽管如此,我还是不明白为什么第一个变体在推送视图控制器的上下文中不起作用。任何人的想法?它只是一个错误吗?