Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 什么';iOS 6-(BOOL)应该自动旋转的要点是什么?_Objective C_Uiviewcontroller_Ios6 - Fatal编程技术网

Objective c 什么';iOS 6-(BOOL)应该自动旋转的要点是什么?

Objective c 什么';iOS 6-(BOOL)应该自动旋转的要点是什么?,objective-c,uiviewcontroller,ios6,Objective C,Uiviewcontroller,Ios6,据我所知,在iOS 6上正确的做法是编写如下代码来处理自动旋转: // iOS 6 - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } 而不是写作 // pre-iOS 6 support - (BOOL)shouldAutorotateToInterfaceOri

据我所知,在iOS 6上正确的做法是编写如下代码来处理自动旋转:

// iOS 6
- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
而不是写作

// pre-iOS 6 support
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    BOOL retVal = UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
    return retVal;
}

老实说,我认为iOS 6之前的版本要清楚得多:我不明白有两种方法来处理自动旋转的意义,特别是因为我在所有示例中都看到了
-(BOOL)shouldAutorotate
返回
YES
。我遗漏了什么吗?

新API允许您保存一个调用以获取当前设备方向:两个问题,即

  • 无论新方向如何,应用程序是否应自动旋转,以及
  • 设备支持什么方向
通常是静态应答,而不打电话检查当前方向。当一个屏幕有多个由单独的视图控制器控制的视图时,节约变得更加重要

由于iOS正在调用应用程序的
shouldAutorotate
,以响应来自加速计的事件,因此它已经知道了新的方向;如果你的应用回答“是”,iOS就可以根据支持的方向列表检查当前方向,并在你的应用不查询当前方向的情况下做出决定


在你的应用程序需要根据新方向决定自动旋转的情况下,新API并不比旧API差,因此这是一个“双赢”的局面。

实际上更糟。UIInterfaceOrientationIsLandscape不会告诉我界面是纵向还是纵向颠倒。当我们需要告诉“是的,旋转,但仅当您想旋转到纵向”时,我们现在要做什么?我现在无法对照UIInterfaceOrientationMaskPortrait检查“toInterfaceOrientation”,因为它不在新的“shouldAutorotate”中。