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
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM