美文网首页
iOS13 persent 适配

iOS13 persent 适配

作者: 怕腥的鱼 | 来源:发表于2019-11-18 14:54 被阅读0次

由于升级Xcode适配iOS13,导致modalPresentationStyle 默认值变成了UIModalPresentationPageSheet,而我们APP里原本都是基于全屏去设计的,苹果这一修改,导致头部空出一片不说,还可能导致原本设计在底部的内容无法正常显示。
方案一:手动每次 present的时候,都去修改它的 modalPresentationStyle = UIModalPresentationFullScreen
当然这是最笨的方法
方案二:在需要persent的页面,init方法中,添加 self.modalPresentationStyle = UIModalPresentationFullScreen
但是找出这些页面,其实并不容易,也繁琐
方案三:利用UIViewController 分类的方法,替换掉 原来present方法,在每次present的时候,判断viewControllerToPresent.modalPresentationStyle == UIModalPresentationPageSheet 然后手动把 modalPresentationStyle改成 UIModalPresentationFullScreen
代码如下:

@implementation UIViewController (Present)

+ (void)load {
    Method originAddObserverMethod = class_getInstanceMethod(self, @selector(presentViewController:animated:completion:));
    Method swizzledAddObserverMethod = class_getInstanceMethod(self, @selector(JF_presentViewController:animated:completion:));
    method_exchangeImplementations(originAddObserverMethod, swizzledAddObserverMethod);
}


- (void)JF_presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
    if (@available(iOS 13.0, *)) {
        if (viewControllerToPresent.modalPresentationStyle == UIModalPresentationPageSheet) {
            viewControllerToPresent.modalPresentationStyle = UIModalPresentationFullScreen;
        }
        [self JF_presentViewController:viewControllerToPresent animated:flag completion:completion];
    } else {
        [self JF_presentViewController:viewControllerToPresent animated:flag completion:completion];
    }
}

这样的话,对于其他modalPresentationStyle,不做修改,保持原来的。全局把所有的UIModalPresentationPageSheet 替换成了UIModalPresentationFullScreen

以最小的修改量,完成最安全,最完善的需求,perfect!~

相关文章

  • iOS13 persent 适配

    由于升级Xcode适配iOS13,导致modalPresentationStyle 默认值变成了UIModalPr...

  • iOS13 适配问题 看这一篇就够了

    技术参考: apple login IOS13适配-详细 iOS 13 适配(持续更新中) iOS13适配 掘金 ...

  • iOS 13适配

    技术参考: apple login IOS13适配-详细 iOS 13 适配(持续更新中) iOS13适配 掘金 ...

  • 暗黑模式开发

    iOS13暗黑模式适配(项目开发版) iOS 13 DarkMode 暗黑模式 IOS 暗黑模式适配---基础适配

  • iOS13适配更新总结

    前言: iOS13的API的变动和适配问题,我从新特性适配、API 适配、方法弃用、工程适配、SDK 适配、其他问...

  • iOS13适配研究

    iOS13今年秋季会发布,最近深入研究了下公司APP适配iOS13的注意点,适配如下。 1.由于Xcode10移除...

  • iOS13适配

    参考: iOS13 适配踩坑 - 持续更新 iOS 13 适配要点总结 iOS 13 适配要点总结 1、prese...

  • iOS13适配(更新中)

    对于iOS13适配汇总以及遇到的问题注意:以下适配内容,必须适配的会以"必须"标出 1. Dark Model(必...

  • 关于WRNavigationBar iOS12、iOS13导航栏

    集成WRNavigationBar 适配iOS12 iOS13导航栏问题 在修复iOS13下在iPhone11机型...

  • 关于WRNavigationBar iOS12、iOS13导航栏

    集成WRNavigationBar 适配iOS12 iOS13导航栏问题 在修复iOS13下在iPhone11机型...

网友评论

      本文标题:iOS13 persent 适配

      本文链接:https://www.haomeiwen.com/subject/tbfbictx.html