willRotateToInterfaceOrientation:不推荐使用duration。实现viewWillTransitionToSize:withTransitionCoordinator

时间:2017-12-12 23:03:12

标签: ios objective-c xcode

我将xcode更新为xcode9后得到了一份弃用警告列表,我不知道如何修复它

  • 'willRotateToInterfaceOrientation:duration:'不推荐使用:首先在iOS 8.0中弃用 - 实现viewWillTransitionToSize:withTransitionCoordinator:而不是
  • 'willAnimateRotationToInterfaceOrientation:duration:'不推荐使用:首先在iOS 8.0中弃用 - 实现viewWillTransitionToSize:withTransitionCoordinator:而不是
  • 'didRotateFromInterfaceOrientation:'已弃用:首先在iOS 8.0中弃用
  • 'interfaceOrientation'已弃用:首先在iOS 8.0中弃用

    @org.springframework.transaction.annotation.Transactional(timeout = 123) // 123 sec
    

1 个答案:

答案 0 :(得分:2)

我只是在寻找同样的东西,并在iOS文档中找到了一些东西,并在阅读之后,因为我的用户仍然拥有iOS 8.我保留了旧的两个功能并添加了新的功能。

// old ones
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    [self handleInterfaceOrientation];
}

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    [self handleInterfaceOrientation];
}
// the new method
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
        // what ever you want to prepare
    } completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
        [self handleInterfaceOrientation];
    }];
}

- (void)handleInterfaceOrientation {
    if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
         // Landscape
    } else {
        // Portrait
    }
}