Objective c 什么';iOS 6-(BOOL)应该自动旋转的要点是什么?
据我所知,在iOS 6上正确的做法是编写如下代码来处理自动旋转: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
- (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允许您保存一个调用以获取当前设备方向:两个问题,即
- 无论新方向如何,应用程序是否应自动旋转,以及
- 设备支持什么方向
shouldAutorotate
,以响应来自加速计的事件,因此它已经知道了新的方向;如果你的应用回答“是”,iOS就可以根据支持的方向列表检查当前方向,并在你的应用不查询当前方向的情况下做出决定
在你的应用程序需要根据新方向决定自动旋转的情况下,新API并不比旧API差,因此这是一个“双赢”的局面。实际上更糟。UIInterfaceOrientationIsLandscape不会告诉我界面是纵向还是纵向颠倒。当我们需要告诉“是的,旋转,但仅当您想旋转到纵向”时,我们现在要做什么?我现在无法对照UIInterfaceOrientationMaskPortrait检查“toInterfaceOrientation”,因为它不在新的“shouldAutorotate”中。