setStatusBarOrientation:animated:在iOS 6中不起作用

flo*_*vdu 6 cocoa-touch objective-c uiinterfaceorientation autorotate ios6

在用户完成观看视频(允许以横向模式观看)之前,我已经使用此代码强制将方向更改回纵向,然后将视频视图控制器从导航控制器上弹出:

//set statusbar to the desired rotation position
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO];

//present/dismiss viewcontroller in order to activate rotating.
UIViewController *mVC = [[[UIViewController alloc] init] autorelease];
[self presentModalViewController:mVC animated:NO];
[self dismissModalViewControllerAnimated:NO];

[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
Run Code Online (Sandbox Code Playgroud)

这完美地工作直到iOS 5.1.1.我甚至试图在另一篇文章中阅读后使用新的现有/解除方法,现在应该使用这些方法:

[self presentViewController:mVC animated:NO completion:NULL];
[self dismissViewControllerAnimated:NO completion:NULL];
Run Code Online (Sandbox Code Playgroud)

问题是它根本不起作用.将视频查看器旋转到横向然后弹出后,我的设置视图(表格视图控制器)返回,但也处于横向模式.

我甚至试过过这里的小费

"该setStatusBarOrientation:animated:方法并未完全弃用.但是,现在只有当supportedInterfaceOrientations最顶层的全屏视图控制器的方法返回0时,它才有效.这使得确保状态栏方向与调用者手中一致的责任."

所以,我尝试了设置标志,强制supportedInterfaceOrientationsreturn 0(调用上面的第一个代码块之前),但它也不起作用.

有人有解决方案吗?感谢您的时间和精力.

Vyt*_*tis 17

setStatusBarOrientation方法改变了一点行为.根据Apple文档:

setStatusBarOrientation:animated:方法不会被完全弃用.现在,只有当最顶层的全屏视图控制器的supportedInterfaceOrientations方法返回0时,它才有效

  • 这很奇怪,因为文档也说"此方法返回的值不能为0" (3认同)

nic*_*las 2

您的根视图控制器应该对该方法回答 false,shouldAutorotate以便您的应用程序响应setStatusBarOrientation:animated

来自 Apple 文档:“但是,如果您的应用程序具有可旋转窗口内容,则不应使用此方法任意设置状态栏方向”

要理解这一点,在该方法中放置一个断点shouldAutorotate,您将看到在设置状态栏方向后它被称为 juste 。