iOS 8 Rotation Methods Deprecation - Backwards Compatibility

后端 未结 6 1534
谎友^
谎友^ 2020-11-27 02:35

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

  • willRotateToInterfaceOrientation:duration:
  • didRotateFro
6条回答
  •  借酒劲吻你
    2020-11-27 03:27

    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)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 context) {
            [self willAnimateRotationToInterfaceOrientation:toOrientation duration:[context transitionDuration]];
        } completion:^(id 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];
    

提交回复
热议问题