1.iOS 13以后modalPresentationStyle的變化
iOS 13系統(tǒng)之前 modalPresentationStyle 的默認(rèn)值是UIModalPresentationFullScreen = 0障般,這時(shí)候模態(tài)推出的控制器是全屏展示的。但iOS 13系統(tǒng)以后modalPresentationStyle的默認(rèn)值變成了UIModalPresentationAutomatic API_AVAILABLE(ios(13.0)) = -2,這時(shí)候如果你還是采用默認(rèn)的值洽洁,那么模態(tài)推出的控制器就不是全屏展示的吊履。iOS 13 的 presentViewController 默認(rèn)有視差效果廓推,模態(tài)出來(lái)的界面現(xiàn)在默認(rèn)都下滑返回颓帝。
2.使用hook方法實(shí)現(xiàn)全局控制励堡。
如果是以前的老項(xiàng)目中使用模態(tài)谷丸,但沒(méi)有設(shè)置modalPresentationStyle的值,那么要不想每個(gè)界面都設(shè)置下应结,可以使用hook方法刨疼。你需要新建一個(gè)UIViewControl的分類(lèi),然后重寫(xiě)load方法鹅龄,代碼如下:
UIViewController+ChangeUI.h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIViewController (ChangeUI)
@end
NS_ASSUME_NONNULL_END
UIViewController+ChangeUI.m
//自動(dòng)調(diào)的揩慕,不需要單獨(dú)在導(dǎo)入頭文件調(diào)用
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
swizzling_exchangeMethod([self class], @selector(presentViewController:animated:completion:), @selector(myPresentViewController:animated:completion:));
});
}
- (void)myPresentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
//設(shè)置滿屏,不需要小卡片
if(@available(iOS 13.0, *)) {
viewControllerToPresent.modalPresentationStyle = UIModalPresentationFullScreen;
}
[self myPresentViewController:viewControllerToPresent animated:flag completion:completion];
}
上面代碼我只列舉了部分扮休,詳細(xì)的可以看下我寫(xiě)的 demo 迎卤,如果寫(xiě)的有什么問(wèn)題,歡迎下方評(píng)論