UIViewController的modalPresentationStyle屬性,在iOS13之前默認值為UIModalPresentationFullScreen,iOS13中蘋果將默認值改為了UIModalPresentationAutomatic债查。
而這個萬惡的UIModalPresentationAutomatic蛙粘,蘋果文檔只寫了一句話:
For most view controllers, UIKit maps this style to the UIModalPresentationPageSheet style, but some system view controllers may map it to a different style.
所以幾乎所有使用了custom presentViewController的頁面全部會變成這個樣紙:
image.png
為了保持iOS13與老版本的UI一致艰猬,最簡單的辦法就是全局將UIViewcontroller的modalPresentationStyle屬性改回UIModalPresentationFullScreen聪富。
這里我沒太深入的思考,用runtime交換了下modalPresentationStyle的get方法玻靡,把我自己hack的get方法return出UIModalPresentationFullScreen就行了结榄。
@implementation UIViewController (MDAdditions)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
SEL sel = @selector(modalPresentationStyle);
SEL swizzSel = @selector(swiz_modalPresentationStyle);
Method method = class_getInstanceMethod([self class], sel);
Method swizzMethod = class_getInstanceMethod([self class], swizzSel);
BOOL isAdd = class_addMethod(self, sel, method_getImplementation(swizzMethod), method_getTypeEncoding(swizzMethod));
if (isAdd) {
class_replaceMethod(self, swizzSel, method_getImplementation(method), method_getTypeEncoding(method));
}else{
method_exchangeImplementations(method, swizzMethod);
}
});
}
- (UIModalPresentationStyle)swiz_modalPresentationStyle {
return UIModalPresentationFullScreen;
}
@end
當(dāng)然重寫presentViewController:方法之類的也可以,個人感覺區(qū)別不大囤捻。
有其他更好的改進意見歡迎提出臼朗。