Ios 应该在iPhone上调用AutoRotate,但不能在iPad上调用

Ios 应该在iPhone上调用AutoRotate,但不能在iPad上调用,ios,shouldautorotate,Ios,Shouldautorotate,我有一个适用于iOS 8/9的通用应用程序,其中包含一个MainstryBoard_iPhone和一个MainstryBoard_iPad。故事板中的入口点是带有选项卡栏的RootViewController。RootViewController非常简单 - (void)viewDidLoad { [(VIBAppDelegate *)[[UIApplication sharedApplication] delegate] setRootViewController:self]; self.in

我有一个适用于iOS 8/9的通用应用程序,其中包含一个MainstryBoard_iPhone和一个MainstryBoard_iPad。故事板中的入口点是带有选项卡栏的RootViewController。RootViewController非常简单

- (void)viewDidLoad
{
[(VIBAppDelegate *)[[UIApplication sharedApplication] delegate] setRootViewController:self];
self.interfaceOrientationMask = UIInterfaceOrientationMaskAll;
self.preferredOrientation = UIInterfaceOrientationMaskAll;
[super viewDidLoad];}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return self.interfaceOrientationMask;
}

- (BOOL)shouldAutorotate{
return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    UIViewController *currentVC = self.selectedViewController;
    if ([currentVC respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)]) {
        UIInterfaceOrientation orientation = [currentVC preferredInterfaceOrientationForPresentation];
        return orientation;
    }else{
    return self.preferredOrientation;
    }
}
当我在iPhone上启动此应用程序时,在应用程序启动期间以及设备旋转时,都会调用支持的InterfaceOrientation和shouldAutorotate方法。当我在iPad上启动应用程序时,它们从未被调用。在这两种情况下,都会按预期调用viewDidLoad函数

我对这件事困惑了好几个小时。除了布局之外,我看不出故事板有什么不同。这两种设备类型都允许Info.plist文件中的所有4个方向和其他相关键

<key>UIMainStoryboardFile</key>
<string>MainStoryboard_iPhone</string>
<key>UIMainStoryboardFile~ipad</key>
<string>MainStoryboard_iPad</string>
<key>UIStatusBarHidden</key>
<true/>
<key>UIStatusBarHidden~ipad</key>
<true/>
<key>UIStatusBarStyle</key>
<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>
UIMainStoryboardFile
主电路板
UIMainStoryboardFile~ipad
主电路板
UIStatusBarHidden
UIStatusBarHidden~ipad
UIStatusBarStyle
UI支持接口方向
UIInterfaceOrientationPortrait
UIInterface方向和左视图
UIInterfaceOrientationAndscapeRight
UIInterfaceOrientation上下方向图
UI支持界面方向~ipad
UIInterfaceOrientationPortrait
UIInterfaceOrientation上下方向图
UIInterface方向和左视图
UIInterfaceOrientationAndscapeRight

在shouldAutorotate函数中放置断点表明UIWindow正在调用is _shouldAutorotateToInterfaceOrientation:CheckForDiskIssal:is。。。它由UIApplicationMain调用。这是意料之中的

在iOS 9上,默认情况下,iPad应用会选择iPad多任务处理。这意味着它必须在任何时候采取所有方向。由于您没有选择退出iPad多任务处理,运行时假设您在任何时候都采用所有方向,因此它不需要麻烦问您允许什么方向,因为它已经知道答案(所有方向)。

好的,所以。。。因为在iPad上,你允许所有四种方向,而且
支持的接口方向
也返回所有方向,那么问题出在哪里?应用程序正在旋转,对吗?这就是你要说的,对吗?如果你注意到supportedInterfaceOrientationMask返回一个类变量的值。此变量由各种视图控制器设置,以控制每个选项卡允许的特定方向。这在iPhone上起作用,因为这些与方向相关的方法都是在设备旋转时调用的。在iPad上,它们从未被称为“无法控制方向”。为什么在一个平台上调用它们而不是在另一个平台上调用它们是毫无意义的。仅供参考,它不是一个类变量。这是一个实例变量。好的,在这里看到答案:我想你会发现,如果你选中这个复选框,一切都会好起来。首先,你是对的,这是一个实例变量。我的错误。我的解决方案是观察旋转,然后使用仿射变换将其旋转到正确的方向。这并不理想,因为操作系统先旋转它,然后我再旋转回来。我希望有一个更平滑的方法来处理,但这已经足够好了。我想这可能与问题有关。我刚刚完成了iOS 9多任务应用程序的改造,但有一个视图需要修复。我需要修改应用程序的这一部分……如果你在info.plist中添加UIRequiresFullScreen=YES,那么至少应该在iOS 12上的iPad上调用shouldAutorotate。@poGUIst是的,我就是这么说的。如果您添加UIRequiresFullScreen=YES,则您选择退出iPad多任务处理。但OP没有这样做。因此,运行时不会询问有关方向的问题;它已经知道所有的答案了。