这并没有回答如何更改设备方向,而是提供可能对您有所帮助的附加信息。
iOS 6 UI 界面方向 - shouldAutorotateToInterfaceOrientation:不工作
方法 shouldAutorotateToInterfaceOrientation: 在 iOS 6 中不受支持。它已弃用。以防万一如果你是一个新手,只是盯着可可工作,想知道为什么你的视图控制器在 iOS 6 中搞砸了而在 iOS 5 中完美,只要知道 shouldAutorotateToInterfaceOrientation: 不再受支持.即使它可能适用于 Xcode 4 到 4.3,但它不适用于 Xcode 4.5。
Apple 提供了一种新方法以更简洁的方式完成这件事。您改为使用 supportedInterfaceOrientations。它返回视图控制器支持的所有界面方向,一个界面方向值的掩码。
UIInterfaceOrientationMask 枚举:
这些常量是用于指定视图控制器支持的界面方向的掩码位。
typedef enum {
UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
UIInterfaceOrientationMaskLandscape =
(UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
UIInterfaceOrientationMaskAll =
(UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
UIInterfaceOrientationMaskAllButUpsideDown =
(UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
UIInterfaceOrientationMaskLandscapeRight),
} UIInterfaceOrientationMask;
使用 shouldAutorotateToInterfaceOrientation: 方法:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return UIInterfaceOrientationIsLandscapeRight(toInterfaceOrientation);
}
使用supportedInterfaceOrientations方法:
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeRight;
}
这些是 UIViewController 在 iOS6 中添加的关于方向的方法
UIViewController preferredInterfaceOrientationForPresentation
UIViewController shouldAutorotate
UIViewController supportedInterfaceOrientations
在 iOS6 中向 UIApplication 添加了有关方向的方法
UIApplication supportedInterfaceOrientationsForWindow:
UIInterfaceOrientationMask