美文网首页
runtime方法全局解决iOS13模态试图不全屏显示问题

runtime方法全局解决iOS13模态试图不全屏显示问题

作者: Silence_xl | 来源:发表于2020-06-06 01:42 被阅读0次

    给UIViewController添加分类SKPModel

    1.分类的.h文件

    #import <UIKit/UIKit.h>
    
    NS_ASSUME_NONNULL_BEGIN
    
    @interface UIViewController (SKPModel)
    
    @end
    
    NS_ASSUME_NONNULL_END
    

    2.分类的.m文件

    #import "UIViewController+SKPModel.h"
    #import <objc/runtime.h>
    
    @implementation UIViewController (SKPModel)
    
    +(void)load{
           Method m1 = class_getInstanceMethod([self class], @selector(presentViewController:animated:completion:));
           Method m2 = class_getInstanceMethod([self class], @selector(skp_presentViewController:animated:completion:));
           method_exchangeImplementations(m1, m2);
    }
    - (void)skp_presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion{
        viewControllerToPresent.modalPresentationStyle =  UIModalPresentationFullScreen;
        [self skp_presentViewController:viewControllerToPresent animated:flag completion:completion];
    }
    @end
    

    相关文章

      网友评论

          本文标题:runtime方法全局解决iOS13模态试图不全屏显示问题

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