gpt4 book ai didi

ios - willRotateToInterfaceOrientation :duration is deprecated. 实现 viewWillTransitionToSize:withTransitionCoordinator

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:21:50 31 4
gpt4 key购买 nike

将我的 xcode 更新到 xcode9 后,我收到了一个已弃用警告列表,但我不知道如何修复它

  • “willRotateToInterfaceOrientation:duration:”已弃用:首先在 iOS 8.0 中弃用 - 改为实现 viewWillTransitionToSize:withTransitionCoordinator:
  • “willAnimateRotationToInterfaceOrientation:duration:”已弃用:首先在 iOS 8.0 中弃用 - 改为实现 viewWillTransitionToSize:withTransitionCoordinator:
  • 'didRotateFromInterfaceOrientation:' 已弃用:首先在 iOS 8.0 中弃用
  • 'interfaceOrientation' 已弃用:首先在 iOS 8.0 中弃用

    - (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self.view addObserver:self forKeyPath:@"bounds" options:NSKeyValueObservingOptionNew context:nil];

    if (!_viewFirstAppeared) {
    _viewFirstAppeared = YES;

    void(^applyViews)(void) = ^{
    [self.centerController.view removeFromSuperview];
    [self.centerView addSubview:self.centerController.view];

    [self doForControllers:^(UIViewController* controller, IIViewDeckSide side) {
    [controller.view removeFromSuperview];
    [self.referenceView insertSubview:controller.view belowSubview:self.slidingControllerView];
    }];

    [self setSlidingFrameForOffset:_offset forOrientation:_offsetOrientation];
    self.slidingControllerView.hidden = NO;

    self.centerView.frame = self.centerViewBounds;
    self.centerController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.centerController.view.frame = self.centerView.bounds;
    [self doForControllers:^(UIViewController* controller, IIViewDeckSide side) {
    controller.view.frame = self.sideViewBounds;
    controller.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    }];

    [self applyShadowToSlidingViewAnimated:NO];
    };

    if ([self setSlidingAndReferenceViews]) {
    applyViews();
    applyViews = nil;
    }

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.001 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
    if (applyViews) applyViews();
    [self setSlidingFrameForOffset:_offset forOrientation:_offsetOrientation];
    [self hideAppropriateSideViews];
    });

    [self addPanners];

    if ([self isSideClosed:IIViewDeckLeftSide] && [self isSideClosed:IIViewDeckRightSide] && [self isSideClosed:IIViewDeckTopSide] && [self isSideClosed:IIViewDeckBottomSide])
    [self centerViewVisible];
    else
    [self centerViewHidden];
    }
    else if (_willAppearShouldArrangeViewsAfterRotation != UIDeviceOrientationUnknown) {
    for (NSString* key in [self.view.layer animationKeys]) {
    [self.view.layer animationForKey:key].duration);
    }

    [self willRotateToInterfaceOrientation:self.interfaceOrientation duration:0];
    [self willAnimateRotationToInterfaceOrientation:self.interfaceOrientation duration:0];
    [self didRotateFromInterfaceOrientation:_willAppearShouldArrangeViewsAfterRotation];
    }

    [self.centerController viewWillAppear:animated];
    [self transitionAppearanceFrom:0 to:1 animated:animated];
    _viewAppeared = 1;
    }

最佳答案

我只是在搜索完全相同的东西,并在 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
}
}

关于ios - willRotateToInterfaceOrientation :duration is deprecated. 实现 viewWillTransitionToSize:withTransitionCoordinator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47782992/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com