iOS13 present VC方法
![](https://img2018.cnblogs.com/blog/1025493/202001/1025493-20200107163045069-1275651774.png)
更新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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
此文仅为鄙人学习笔记之用,朋友你来了,如有不明白或者建议又或者想给我指点一二,请私信我。liuw_flexi@163.com/QQ群:582039935.
我的gitHub: (学习代码都在gitHub)
https://github.com/nwgdegitHub/