在iOS 8中,界面旋转的方法是deprecated .这包括:
willRotateToInterfaceOrientation:duration:
didRotateFromInterfaceOrientation:
willAnimateRotationToInterfaceOrientation:duration:
替换方法包括:
willTransitionToTraitCollection:withTransitionCoordinator:
viewWillTransitionToSize:withTransitionCoordinator:
如果未实现新的旋转方法,并且项目是使用 iOS 8 SDK 编译的, View Controller 将不会接收调用- 已弃用的旋转方法。
我担心的是:AppStore 中使用 iOS 7 SDK 构建的应用程序会怎样?是否仍会在 iOS 8 设备上调用已弃用的旋转方法?
编辑:
旋转方法仍然被调用,但在 iOS 8 中存在一些变化/问题/错误。
最佳答案
我刚遇到这个问题,我想使用我以前使用的相同方法(至少现在是这样),所以这就是我所做的。
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
//The device has already rotated, that's why this method is being called.
UIInterfaceOrientation toOrientation = [[UIDevice currentDevice] orientation];
//fixes orientation mismatch (between UIDeviceOrientation and UIInterfaceOrientation)
if (toOrientation == UIInterfaceOrientationLandscapeRight) toOrientation = UIInterfaceOrientationLandscapeLeft;
else if (toOrientation == UIInterfaceOrientationLandscapeLeft) toOrientation = UIInterfaceOrientationLandscapeRight;
UIInterfaceOrientation fromOrientation = [[UIApplication sharedApplication] statusBarOrientation];
[self willRotateToInterfaceOrientation:toOrientation duration:0.0];
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self willAnimateRotationToInterfaceOrientation:toOrientation duration:[context transitionDuration]];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self didRotateFromInterfaceOrientation:fromOrientation];
}];
}
我仍然不确定是否应该在动画 block 之外使用它,因为我没有持续时间。
[self willRotateToInterfaceOrientation:toOrientation duration:0.0];
关于iOS 8 旋转方法弃用 - 向后兼容性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25238620/