这是一个比任何事情更多的观察,因为我似乎找到了一个解决方法......
当它在一个已被推送到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;
}
Run Code Online (Sandbox Code Playgroud)
以下调用已取得:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
Run Code Online (Sandbox Code Playgroud)
要解决这个UIDeviceOrientationUnknown问题,我现在使用以下代码:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
etc.
} else {
etc.
}
Run Code Online (Sandbox Code Playgroud)
......每次都有效.
尽管如此,我仍然不明白为什么第一个变体在推送视图控制器的上下文中不起作用.想法有人吗?这只是一个错误吗?
iphone uinavigationcontroller uiinterfaceorientation uideviceorientation