【发布时间】:2011-08-17 10:07:28
【问题描述】:
我需要确保当我的UIViewController 加载时,它会根据需要旋转。
我已经实现了shouldAutorotateToInterfaceOrientation 方法并且它一切正常,除了当应用程序第一次加载(当 iphone 处于横向模式时)或从 UIViewController 这是纵向模式时,interfaceOrientation 和 @ 987654324@ 总是返回纵向模式!
我一直在阅读博客甚至一些 SO 问题,但似乎都没有解决根本问题。
我正在使用标准 UINavigationController 应用程序。所以第一个视图是第一个压入堆栈的控制器。我也试过询问 self.navigationController 的方向,也没有运气。
非常感谢这里的任何帮助。
编辑:这是我的 viewWillAppear 代码
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:YES animated:NO];
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
[self setPortraitMode];
else
[self setLandscapeMode];
}
编辑 2
这是我打印当前的方式
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
NSLog(@"currentDevice: %d", (int)orientation);
NSLog(@"statusbar: %d", (int)[UIApplication sharedApplication].statusBarOrientation);
NSLog(@"nav controller: %d", (int)self.navigationController.interfaceOrientation);
NSLog(@"interface orientation: %d", (int)self.interfaceOrientation);
他们都打印出“1”
但是当我将此代码放入 willRotateToInterfaceOrientation 方法时,它们会打印出正确的 int 值(1、2、3 或 4)。
【问题讨论】:
-
你找到这个问题的答案了吗?
-
记不清了,但是看回复,我不这么认为:(
标签: iphone objective-c ipad orientation