我的应用程序中有两个 View ; “计算器”和“磁带”。我可以单击计算器内的按钮来访问磁带,反之亦然。我按照下面的代码设置了旋转,大多数情况下都工作正常。
但是,如果我将计算器 View 或磁带 View 旋转为横向,然后如果我尝试访问其他 View ,界面就会变得一团糟,就像它无法识别设备已经旋转一样。有什么建议吗?
- (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
}
}
最佳答案
在每个 View 都会出现的 View 中写入这些代码。
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.
}
关于ios - ios6 中的自动旋转未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21992563/