iOS13 present VC方法

更新iOS 13之后,发现我们工程模态展示的视图默认是非全屏的。经过百度一番(百度就够了)。因为苹果在iOS13改了默认的样式。在iOS13前,该值默认为UIModalPresentationFullScreen。而在 iOS13 中默认值变为了UIModalPresentationAutomatic。所以就出现了类似sheet 的非全屏样式。如果考虑到全工程一一在present前加一句vc.modalPresentationStyle = UIModalPresentationFullScreen; 麻烦, 可以hook全局处理。
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface UIViewController (LGModel)
-(void)lg_presentViewController:(UIViewController*)viewControllerToPresent animated:(BOOL)flag completion:(void(^)(void))complete;
@end

NS_ASSUME_NONNULL_END
#import "UIViewController+LGModel.h"

#import <objc/runtime.h>

@implementation UIViewController (LGModel)

+(void)load{
    [super load];
    
    SEL exchangeSel = @selector(lg_presentViewController: animated: completion:);
    SEL originalSel = @selector(presentViewController: animated: completion:);
    method_exchangeImplementations(class_getInstanceMethod(self.class, originalSel), class_getInstanceMethod(self.class, exchangeSel));
}

-(void)lg_presentViewController:(UIViewController*)viewControllerToPresent animated:(BOOL)flag completion:(void(^)(void))completion{
    viewControllerToPresent.modalPresentationStyle = UIModalPresentationFullScreen;
    [self lg_presentViewController:viewControllerToPresent animated:flag completion:completion];
}

@end

 



作者:Virusboo
链接:https://www.jianshu.com/p/f3be643e66e3
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
posted @ 2020-01-07 16:31  liuw_flexi  阅读(1863)  评论(0编辑  收藏  举报