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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25238620/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 01:47:35  来源:igfitidea点击:

iOS 8 Rotation Methods Deprecation - Backwards Compatibility

iosrotationios8

提问by fabb

In iOS 8, the methods for interface rotation are deprecated. This includes:

在 iOS 8 中,不推荐使用界面旋转的方法。这包括:

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

The replacement methods include:

更换方法包括:

  • willTransitionToTraitCollection:withTransitionCoordinator:
  • viewWillTransitionToSize:withTransitionCoordinator:
  • willTransitionToTraitCollection:withTransitionCoordinator:
  • viewWillTransitionToSize:withTransitionCoordinator:

If the new rotation methods are not implemented, and a project is compiled with the iOS 8 SDK, the view controllers -will not receive calls- to the deprecated rotation methods.

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

My concern is this: What happens to an app already in the AppStore built with the iOS 7 SDK? Will the deprecated rotation methods still be called on an iOS 8 device or not?

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

EDIT:

编辑:

The rotation methods are still called, but there exist some changes/issues/bugs in iOS 8.

旋转方法仍然被调用,但在 iOS 8 中存在一些变化/问题/错误。

Also UIScreenis now interface oriented

现在也是UIScreen面向界面的

采纳答案by mluisbrown

The rotation methods are deprecated in the iOS 8 SDK. This will have no effect at all on apps built with the iOS 7 SDK, even running in iOS 8 and probably several future versions of iOS.

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

As an example, the fontproperty of UIButtonhas been deprecated since iOS 3.0 and is still available in iOS 7.0.

例如,从 iOS 3.0 开始不推荐使用的font属性,UIButton并且在 iOS 7.0 中仍然可用。

回答by Camo

I just had this issue and I wanted to use the same methods that I was using before (at least for now), so this is what I did.

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

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

}

I'm still not sure if I should use this outside of the animation block since I don't have the duration.

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

    [self willRotateToInterfaceOrientation:toOrientation duration:0.0];

回答by Jordan H

The deprecated rotation methods you've listed are still called when the app is run on iOS 8+ devices. If you are supporting iOS 7, you may continue to use them without issue. If you are only supporting iOS 8+, it would be wise to use the non-deprecated methods instead.

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

However, do note that if you implement the new rotation methods and the deprecated ones in the same view controller, when run on iOS 7 the deprecated methods will be called, and on iOS 8+ it will only call the new methods that have replaced those that are deprecated.

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

For example, if you only implement willRotateToInterfaceOrientation, this method will be called when run on iOS 7 and 8. If you then add viewWillTransitionToSize, iOS 7 will still call willRotateToInterfaceOrientationbut iOS 8 will not, instead it will only call viewWillTransitionToSize.

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

回答by Julian Król

I would check that specific case to have 100% of confidence but I do not expect any troubles. I would also recommend you watching session 216 Building Adaptive Apps with UIKitfrom WWDC 2014to get more informations. It looks like the depreciated methods are not called so the app should be updated to work properly with devices running iOS 8.

我会检查那个特定案例以有 100% 的信心,但我不希望有任何麻烦。我也建议你在看会话216 Building Adaptive Apps with UIKitWWDC 2014,以获得更多信息。看起来折旧的方法没有被调用,所以应该更新应用程序以在运行 iOS 8 的设备上正常工作。

回答by fabb

The rotation methods still work, BUTthere exist other issues:

旋转方法仍然有效,存在其他问题:

回答by tyoc213

For me, here we rotate "things manually" with some calculations and a plist file that track the size of headers and things like that (so if we want to change something buttons and so on, we only change this plist not all individual xibs). And all our rotation code is inside willLayoutSubviewsso all things are correct even on new iOS8... except for I Also I did see that for new ios8 [[UIScreen mainScreen] bounds].size.widthnow return the width acording to device orientation not to device real size.

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

I will post this to other thread:

我会将此发布到其他线程:

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