iOS 9 supportedInterfaceOrientations不起作用
我有一个UIViewController
与下面的代码:
- (BOOL) shouldAutorotate { return NO; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationPortrait; }
我没有使用UINavigationController
。 当这个UIViewController
被显示时,设备仍然会旋转到横向。 我针对iOS 9,这里有什么问题?
所以问题是我已经在info.plist
定义了允许的方向,这显然会覆盖你在整个项目中任何其他地方做的任何事情。
为了纠正这个问题,我从info.plist
删除了条目,并在项目设置中定义了它们。 现在一切按预期工作。
我不认为布赖恩的答案是有效的,因为在项目设置中改变方向也会改变info.plist
为@mrhangz的评论。
如果问题只是iOS9,可能是由于iPad的iOS9的新function称为Split view
。iOS9启用了Split view
在默认情况下,特别是iPad设备,请参阅这里的苹果文档。
split view
迫使您的应用程序支持所有视图中的所有方向一旦采用。因此,如果您在info.plist
或目标常规设置中设置了所有方向支持,则默认情况下支持split view
,但将忽略方向设置,虽然supportedInterfaceOrientations
在你的viewController和支持所有的方向。
在写入文档时,如果您在目标设置中选中了“ Requires full screen
,那么您的应用将不支持split view
。现在,您可以再次在代码中控制方向。
我已经尝试了很多解决scheme,但是解决scheme的正确答案是:
ios 8和9,不需要编辑info.plist。
- (BOOL) shouldAutorotate { return NO; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations { return (UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown); }
可能的方向
UIInterfaceOrientationUnknown
设备的方向不能确定。
UIInterfaceOrientationPortrait
该设备处于纵向模式,设备保持直立,底部的主页button。
UIInterfaceOrientationPortraitUpsideDown
该设备是纵向模式,但倒挂,设备保持直立,顶部的主页button。
UIInterfaceOrientationLandscapeLeft
设备处于横向模式,设备保持直立,左侧的主页button。
UIInterfaceOrientationLandscapeRight
设备处于横向模式,设备直立,主页button位于右侧。