【发布时间】:2011-10-16 09:45:07
【问题描述】:
为了更好的用户体验,我的代码中包含以下内容:
if (allowLandscape) {
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation) || toInterfaceOrientation == UIInterfaceOrientationPortrait;
}
else {
return toInterfaceOrientation == UIInterfaceOrientationPortrait;
}
因此,如果将 allowLandscape 设置为 YES,则用户可以在所有典型设备方向上使用该应用程序。但是 allowLandscape 可以随时设置为 NO,我想将 UIViewController 旋转回纵向。
以下代码仅在用户手动更改设备方向时才有效。所以如果allowLandscape 是YES,他可以旋转设备并且界面方向跟随方向变化。但是,如果他保持横向,并且 allowLandscape 将设置为 NO,他将保持横向,直到他将 iPhone 移动到纵向 - 如果 allowLandscape 仍然为 NO,则无法更改纵向。
我想要完成的是调用一些方法,如果可能的话,强制 ViewController 用动画刷新它的方向。
调用方法:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
只改变状态栏,但界面保持原来的方向。我不想使用任何未记录的 API。
【问题讨论】:
-
就我个人而言,我不会实现操作系统中已经内置的功能。
-
嗯,什么功能?如何禁用横向并通过带有动画的代码将方向翻转为纵向?我说的是一个 UIViewController。
-
也许我误解了你的问题(即使在重读之后)。用户可以通过任务菜单锁定和解锁方向(双击home键然后向右滑动)。
标签: cocoa-touch uiviewcontroller uiinterfaceorientation interface-orientation