为了获得更好的用户体验,我的代码中包含以下内容:
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。