iOS13 presentViewController 样式适配

一、iOS13 开始运行应用程序调用present方法的时候会出现显示效果的变化(看起来好像挺好看的),因为在iOS13中modalPresentationStyle的默认改为UIModalPresentationAutomatic,而在之前默认是UIModalPresentationFullScreen
iOS13 presentViewController 样式适配_第1张图片
效果图
二、 ** 重点!重点!重点!** 生命周期会发生变化,例如:page1 present page2,page2 dismiss时,page1的 viewWillAppear 等相关的生命周期方法将不会执行,还有页面高度也会不同,为了避免不必要的问题产生,所以建议大家一定要手动处理modalPresentationStyle设置为UIModalPresentationFullScreen

修改方式涉及两种情况

1.无nav情况

    UIViewController *viewController = [[UIViewController alloc] init];
    viewController.modalPresentationStyle = UIModalPresentationFullScreen;
    [self persentViewController:viewController animated:YES completion:nil]; 

2.有nav的情况

     UIViewController *viewController = [[UIViewController alloc] init]; 
     UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController];
     nav.modalPresentationStyle = UIModalPresentationFullScreen;
     [self.navigationController presentViewController:nav animated:YES completion:nil];

躺赢源码在此,放入工程即可* demo

你可能感兴趣的:(iOS13 presentViewController 样式适配)