自动旋转ios6不按预期工作

自动旋转ios6不按预期工作

问题描述:

我在我的应用程序中有两个视图; “计算器”和“磁带”。我可以点击计算器里面的按钮来找到磁带,反之亦然。我按照下面的代码设置了轮转,大部分时间都能正常工作。自动旋转ios6不按预期工作

但是,如果我将计算器视图或磁带视图旋转到横向,然后如果我尝试访问其他视图,界面就会全部混乱,就像它无法识别该设备已被旋转一样。有什么建议么?

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    [self doLayoutForOrientation:toInterfaceOrientation]; 
} 


- (void)doLayoutForOrientation:(UIInterfaceOrientation)orientation { 
if (UIInterfaceOrientationIsPortrait(orientation)) 
{ 
//set the frames here 
} 
else 
{ 
//set the frames here 
} 
} 
+0

当您从已经旋转的视图转到另一个视图(比如磁带)时,设备无法识别该视图已被更改。 –

+0

所以你需要检查设备的当前方向,在视图中会出现下一个视图并调整视图 –

+0

好极了,像梦一样工作。 –

这些代码写在视图中会出现每个视图。

UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
{ 
//adjust the view for landscape 
} 
else if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
//adjust the view for portrait. 
}