ZFPlayer库针对iOS15及以上系统适配(解决横屏闪退问题)

在iOS 15 及以上系统,横屏控制器ZFLandscapeViewController中将CATransaction的提交操作放在animateAlongsideTransition方法的completion回调中,就不会进入completion代码块,横屏时可能会回调,但是回到竖屏时一定不会回调,我临时的解决方案是在iOS 15中将[CATransaction commit]移到旋转前的block中

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator {
    self.rotating = YES;
    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    if (!UIDeviceOrientationIsValidInterfaceOrientation([UIDevice currentDevice].orientation)) {
        return;
    }
    UIInterfaceOrientation newOrientation = (UIInterfaceOrientation)[UIDevice currentDevice].orientation;
    UIInterfaceOrientation oldOrientation = _currentOrientation;
    if (UIInterfaceOrientationIsLandscape(newOrientation)) {
        if (self.contentView.superview != self.view) {
            [self.view addSubview:self.contentView];
        }
    }
    
    if (oldOrientation == UIInterfaceOrientationPortrait) {
        self.contentView.frame = [self.delegate ls_targetRect];
        [self.contentView layoutIfNeeded];
    }
    self.currentOrientation = newOrientation;
    
    [self.delegate ls_willRotateToOrientation:self.currentOrientation];
    BOOL isFullscreen = size.width > size.height;
    [CATransaction begin];
    [CATransaction setDisableActions:self.disableAnimations];
    [coordinator animateAlongsideTransition:^(id _Nonnull context) {
        if (isFullscreen) {
            self.contentView.frame = CGRectMake(0, 0, size.width, size.height);
        } else {
            self.contentView.frame = [self.delegate ls_targetRect];
        }
        [self.contentView layoutIfNeeded];
        if (@available(iOS 15.0, *)) {
            CGFloat duration = [coordinator transitionDuration];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(duration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [CATransaction commit];
            });
        }
    } completion:^(id _Nonnull context) {
        if (@available(iOS 15.0, *)) {
        } else {
            [CATransaction commit];
        }
        self.disableAnimations = NO;
        [self.delegate ls_didRotateFromOrientation:self.currentOrientation];
        self.rotating = NO;
    }];
}

你可能感兴趣的:(ZFPlayer库针对iOS15及以上系统适配(解决横屏闪退问题))