ios6中的自动旋转没有按预期工作

Posted

技术标签:

【中文标题】ios6中的自动旋转没有按预期工作【英文标题】:Auto-rotation in ios6 not working as expected 【发布时间】:2014-02-24 15:57:15 【问题描述】:

我的应用中有两个视图; “计算器”和“磁带”。我可以单击计算器内的按钮以获取磁带,反之亦然。我按照下面的代码设置了旋转,并且大部分时间都可以正常工作。

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

- (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
 

【问题讨论】:

当您从已旋转的视图转到另一个视图(例如磁带)时,设备无法识别视图已更改。 所以你需要在视图中检查设备的当前方向才会出现下一个视图并调整视图 太棒了,就像做梦一样。 很高兴能帮到你。 【参考方案1】:

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

 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.

【讨论】:

以上是关于ios6中的自动旋转没有按预期工作的主要内容,如果未能解决你的问题,请参考以下文章

自动布局无法按预期工作

视图控制器方向没有按预期工作,我错过了啥?

GLSL 2D 旋转矩阵无法按预期工作

C++ 四元数旋转未按预期工作

Android View Rotation Animation 和 Set Rotation 未按预期工作

自动填充在 Excel 中未按预期工作