我无法弄清楚如何在iOS 6上处理设备旋转。我有三件事需要在旋转设备时单独更改。
我如何在iOS 6中实现这一点,我在iOS 5中完成了所有工作。
这是我到目前为止所做的:
在父UIViewController中:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (BOOL)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
在子视图控制器中:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (BOOL)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
答案 0 :(得分:1)
还有一点可以正确支持iOS6。 iOS 6发行说明草拟了一些事项:
https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html
这个位可能有用:
为了兼容性,仍然实现shouldAutorotateToInterfaceOrientation:方法的视图控制器不会获得新的自动旋转行为。 (换句话说,它们不会回退到使用app,app delegate或Info.plist文件来确定支持的方向。)而是使用shouldAutorotateToInterfaceOrientation:方法来合成将由supportedInterfaceOrientations方法返回的信息。
但是你还应该看看WWDC 2012的Session 236 - 视图控制器的演变。
答案 1 :(得分:0)
如果要在导航堆栈中支持不同的方向,则必须首先继承UINavigationController并覆盖supportedInterfaceOrientations。
- (NSUInteger)supportedInterfaceOrientations
{
//I want to support portrait in ABCView at iPhone only.
//and support all orientation in other views and iPad.
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
{
// find specific view which you want to control.
if ([[self.viewControllers lastObject] isKindOfClass:[ABCView class]])
{
return UIInterfaceOrientationMaskPortrait;
}
}
//support all
return UIInterfaceOrientationMaskAll;
}