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

fab*_*abb 52 rotation ios ios8

在iOS 8中,不推荐使用接口轮换方法.这包括:

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

替代方法包括:

  • willTransitionToTraitCollection:withTransitionCoordinator:
  • viewWillTransitionToSize:withTransitionCoordinator:

如果未实现新的旋转方法,并且使用iOS 8 SDK编译项目,则视图控制器将不会接收调用 - 不推荐的旋转方法.

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

编辑:

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

现在也是UIScreen面向接口的

Cam*_*amo 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];
    }];

}
Run Code Online (Sandbox Code Playgroud)

我仍然不知道我是否应该使用这种动画块外,因为我没有时间.

    [self willRotateToInterfaceOrientation:toOrientation duration:0.0];
Run Code Online (Sandbox Code Playgroud)


mlu*_*own 19

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

例如,自iOS 3.0以来,该font属性UIButton已被弃用,并且仍可在iOS 7.0中使用.

  • 我不知道是谁在没有理由的情况下对此进行投票.答案是对的.我们测试了它.我们的一个应用程序支持iOS 4.3 [企业应用程序],它在iOS8 beta5上完美旋转.如果使用iOS 8 SDK构建应用程序,轮换回拨只会造成麻烦. (5认同)
  • @fabb见[这里](https://developer.apple.com/library/ios/documentation/DeveloperTools/Conceptual/cross_development/Using/using.html#//apple_ref/doc/uid/20002000-SW5)."弃用并不意味着立即从框架或库中删除接口." 并且"已弃用的API可能会从操作系统的未来版本中删除".这就是弃用意味着它可以从操作系统的*future*版本中删除. (3认同)
  • 不要使用xcode 6来构建你的应用程序或轮换将失败. (3认同)

Jor*_*n H 6

当应用程序在iOS 8+设备上运行时,仍会调用您已列出的已弃用的轮播方法.如果您支持iOS 7,则可以继续使用它们而不会出现问题.如果您只支持iOS 8+,那么使用非弃用方法将是明智之举.

但是,请注意,如果在同一视图控制器中实现新的旋转方法和不推荐的旋转方法,则在iOS 7上运行时,将调用已弃用的方法,而在iOS 8+上,它将仅调用已替换这些方法的新方法已弃用.

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