iOS 8轮换方法弃用 - 向后兼容性

时间:2014-08-11 08:15:15

标签: ios rotation ios8

在iOS 8中,界面轮换的方法是deprecated。这包括:

  • willRotateToInterfaceOrientation:duration:
  • didRotateFromInterfaceOrientation:
  • willAnimateRotationToInterfaceOrientation:duration:

替换方法包括:

  • willTransitionToTraitCollection:withTransitionCoordinator:
  • viewWillTransitionToSize:withTransitionCoordinator:

如果没有实现新的旋转方法,并且使用iOS 8 SDK编译项目,则视图控制器将不接收调用 - 添加到已弃用的旋转方法。

我担心的是:使用iOS 7 SDK构建的AppStore中的应用程序会发生什么变化?是否仍会在iOS 8设备上调用已弃用的旋转方法?

修改

仍在调用旋转方法,但iOS 8中存在一些更改/问题/错误。

另外UIScreen is now interface oriented

6 个答案:

答案 0 :(得分:36)

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

- (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];
    }];

}

我还不确定是否应该在动画块之外使用它,因为我没有持续时间。

    [self willRotateToInterfaceOrientation:toOrientation duration:0.0];

答案 1 :(得分:19)

iOS 8 SDK中不推荐使用旋转方法。这对使用iOS 7 SDK构建的应用程序完全没有影响,甚至可以在iOS 8和iOS的未来版本中运行。

例如,自{iOS}起,font UIButton属性已被弃用,并且在iOS 7.0中仍然可用。

答案 2 :(得分:6)

当应用程序在iOS 8+设备上运行时,仍会调用您已列出的已弃用的轮播方法。如果您支持iOS 7,则可以继续使用它们而不会出现问题。如果您只支持iOS 8+,那么最好使用不推荐使用的方法。

但是,请注意,如果在同一个视图控制器中实现新的旋转方法和不推荐的旋转方法,则在iOS 7上运行时,将调用不推荐使用的方法,而在iOS 8+上,它只调用新方法已经取代了那些被弃用的。

例如,如果您只实现willRotateToInterfaceOrientation,则在iOS 7和8上运行时将调用此方法。如果您再添加viewWillTransitionToSize,iOS 7仍会调用willRotateToInterfaceOrientation但是iOS 8不会,而只会调用viewWillTransitionToSize

答案 3 :(得分:2)

我会检查具体案例是否有100%的信心,但我不指望有任何麻烦。我还建议你从WWDC 2014观看会话216 Building Adaptive Apps with UIKit以获取更多信息。看起来不会调用折旧方法,因此应该更新应用程序以使其与运行iOS 8的设备一起正常工作。

答案 4 :(得分:1)

轮换方法仍有效,存在其他问题:

答案 5 :(得分:1)

对我来说,我们在这里手动旋转#34;有一些计算和plist文件跟踪标题和类似的东西的大小(所以如果我们想要更改某些按钮等等,我们只更改此plist而不是所有单独的xib)。我们所有的旋转代码都在willLayoutSubviews内,所以所有的东西都是正确的,即使在新的iOS8上......除了I我也确实看到新的ios8 [[UIScreen mainScreen] bounds].size.width现在返回根据设备方向的宽度而不是设备实际大小。

我会将此帖子发布到其他帖子:

- (BOOL) isIOS8OrAbove{
    float version802 = 1140.109985;
    float version8= 1139.100000; // there is no def like NSFoundationVersionNumber_iOS_7_1 for ios 8 yet?
    NSLog(@"la version actual es [%f]", NSFoundationVersionNumber);
    if (NSFoundationVersionNumber >= version8){
        return true;
    }
    return false;
}
相关问题