【发布时间】:2013-10-22 14:47:37
【问题描述】:
我已经在 IOS 6.0 中实现了带有方向支持的示例代码,它可以正常工作,但是如果我在 ipad 1 (IOS 5.1) 中运行,相同的应用程序不支持方向。我知道 IOS 6.0 不推荐使用 iOS 5.1 中的某些方法如何解决这个问题?
【问题讨论】:
标签: ios uiinterfaceorientation
我已经在 IOS 6.0 中实现了带有方向支持的示例代码,它可以正常工作,但是如果我在 ipad 1 (IOS 5.1) 中运行,相同的应用程序不支持方向。我知道 IOS 6.0 不推荐使用 iOS 5.1 中的某些方法如何解决这个问题?
【问题讨论】:
标签: ios uiinterfaceorientation
您需要在视图控制器中实现旧的旋转方法以支持 iOS 5 或更低版本的旋转。
是的,这些方法已被弃用,但旧版本的 iOS 仍然需要这些方法。
【讨论】:
对于 iOS 6+,请使用这些方法
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
对于 iOS 5.0 和所有以前的使用这个
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
【讨论】:
在 .m 文件中使用以下代码。
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
return NO;
}
else {
return YES;
}
}
这适用于 iOS 5.1、6.1.3 和 7.0.2。
【讨论】: