ios开发之Modal切换场景遇到的bug

tech2023-08-28  92

项目场景:

Code segue: 使用代码UIModalTransitionStylePartialCurl(竖屏翻页效果过渡)切换到新的ViewController后,使用代码dismissViewControllerAnimated:YES返回前一个ViewController时候动画卡死

问题描述:

1.使用代码UIModalTransitionStylePartialCurl(竖屏翻页效果过渡)切换到新的ViewController

//代码实现切换到第四场景 - (IBAction)gotoFourthView:(id)sender { //获取Main.storyboard UIStoryboard * sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; //获取新的viewcontroler FourthViewController * fvc = [sb instantiateViewControllerWithIdentifier:@"fourthview"]; //过度翻页效果 fvc.modalTransitionStyle = UIModalTransitionStylePartialCurl; //过度页面采用modal样式 fvc.modalPresentationStyle = UIModalPresentationFullScreen; //展示新页面 [self presentViewController:fvc animated:YES completion:nil]; }

2.在新ViewController使用代码dismissViewControllerAnimated:YES返回前一个ViewController时候,播放动画会出现卡死现象

//返回上一层页面 - (IBAction)backToPreviosView:(id)sender { UIViewController *presentingVc = self.presentingViewController; // while (presentingVc.presentingViewController) { // presentingVc = presentingVc.presentingViewController; // } if(presentingVc){ [presentingVc dismissViewControllerAnimated:YES completion:nil]; } }

3.如图所示:


原因分析:

提示:这里填写问题的分析: 未知原因


解决方案:

不使用UIModalTransitionStylePartialCurl样式,使用其他3样返回正常,例如: UIModalTransitionStyleCoverVerticalUIModalTransitionStyleFlipHorizontalUIModalTransitionStyleCrossDissolve 如果一定要使用IModalTransitionStylePartialCurl样式,那么返回时候,是否播放动画选择NO [presentingVc dismissViewControllerAnimated: NO completion:nil];
最新回复(0)