iOS 8 旋转方法弃用 - 向后兼容性

标签 ios rotation ios8

在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 中存在一些变化/问题/错误。

还有 UIScreen is now interface oriented

最佳答案

我刚遇到这个问题,我想使用我以前使用的相同方法(至少现在是这样),所以这就是我所做的。

- (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/

相关文章:

math - 绘制带有 3D 顶点的 2D 面

android - 在后置和前置摄像头之间切换

ios - 使用 UIPageViewController 启动 iOS8 时出现黑色状态栏

ios - 我的 TableView 中的数据一次又一次地重新加载?

ios - 是否可以为 Collection View 添加拖动以水平重新加载?

javascript - 如何找到旋转向量的 x,y 坐标

ios - 如何向 uicollection View 添加阴影? ios

ios - SwiftUI 关闭多个模态表

ios - Parallax:在网页中获取视差事件

ios - 我将部署目标设置为 iOS8 ,应用商店显示 "Compatibility: Requires iOS 7.0 or later"。我可以强制应用程序仅安装在 iOS8 中吗?