【发布时间】:2014-10-22 08:39:55
【问题描述】:
我发现 UIViewController shouldAutorotate 方法在 7.1 和 8 之间有一个小的行为变化。
Apple View Controller Programming Guide 声明在执行任何自动旋转之前调用此方法。
但是我注意到,当我简单地禁用 shouldAutorotate(返回 NO)时,该方法会在纵向 -> 横向旋转上调用,但不会在以下横向 -> 纵向旋转上调用。同样,该方法应始终按照我的理解进行调用。在 iOS 8 上运行时会出现这种情况,而在 iOS 7.1 上则不会。
这似乎与 iOS8 调用堆栈中的一个新方法有关:
[UIWindow shouldAutorotateToInterfaceOrientation:checkForDismissal:isRotationDisabled]
我找不到关于此方法及其行为的任何描述,知道在哪里可以找到有关此内部方法的更多信息?
重现此的简单步骤:
- 在 Xcode 中创建一个新的 Single View Application 项目
-
更新您的
ViewController.m以实现 shouldAutorotate- (BOOL)shouldAutorotate { UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; NSLog(@"%s orientation is %@", __PRETTY_FUNCTION__, [self stringFromDeviceOrientation:orientation]); // Disable autorotation of the interface. return NO; } - (NSString *) stringFromDeviceOrientation:(UIDeviceOrientation)uido { NSString *orientation = @"UIDeviceOrientationUnknown"; switch (uido) { case UIDeviceOrientationPortrait: orientation = @"Portrait"; break; case UIDeviceOrientationPortraitUpsideDown: orientation = @"PortraitUpsideDown"; break; case UIDeviceOrientationLandscapeRight: orientation = @"LandscapeRight"; break; case UIDeviceOrientationLandscapeLeft: orientation = @"LandscapeLeft"; break; case UIDeviceOrientationFaceDown: orientation = @"FaceDown"; break; case UIDeviceOrientationFaceUp: orientation = @"FaceUp"; break; default: break; } return orientation; } 在模拟器 iPhone 5s (7.1) 上运行:
shouldAutorotate在切换到横向并返回到纵向时被调用- 在模拟器 iPhone 5s (8.0) 或 iPhone 6 上运行:
shouldAutorotate在切换到横向时被调用,但在切换回纵向时不被调用。
【问题讨论】:
标签: ios objective-c iphone