在iOS 15 及以上系统,横屏控制器ZFLandscapeViewController中将CATransaction的提交操作放在animateAlongsideTransition方法的completion回调中,就不会进入completion代码块,横屏时可能会回调,但是回到竖屏时一定不会回调,我临时的解决方案是在iOS 15中将[CATransaction commit]移到旋转前的block中
-(void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator{self.rotating=YES;[superviewWillTransitionToSize: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<UIViewControllerTransitionCoordinatorContext>_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(iOS15.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<UIViewControllerTransitionCoordinatorContext>_Nonnull context){if(@available(iOS15.0,*)){}else{[CATransaction commit];}self.disableAnimations=NO;[self.delegate ls_didRotateFromOrientation:self.currentOrientation];self.rotating=NO;}];}
作者:CrazySnow
链接:https://www.jianshu.com/p/c4c67270c36c
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
网友评论