我需要确保当我的UIViewController
负载,它根据需要旋转。
我已经实施了shouldAutorotateToInterfaceOrientation
方法及其所有工作正常,除非应用程序首次加载时(当 iphone 处于横向模式时)或从处于纵向模式的 UIViewController 开始时interfaceOrientation
和[[UIDevice currentDevice] orientation]
总是返回肖像模式!
我一直在阅读博客甚至一些SO问题,但它们似乎都没有解决根本问题。
我正在使用标准 UINavigationController 应用程序。所以第一个视图是第一个推入堆栈的控制器。我也尝试询问 self.navigationController 的方向,但也没有成功。
非常感谢这里的任何帮助。
EDIT:这是我的 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];
}
EDIT 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)。