以下为iOS13新引入的模式,为默认模式
UIModalPresentationAutomatic API_AVAILABLE(ios(13.0)) = -2,
以往默认模式为
UIModalPresentationFullScreen = 0,
如若此模式影响到你的界面可用以下方式解决批量此问题
用runtime修改系统方法 presentViewController:animated:completion:
+(void)load{
if (@available(iOS 13.0, *)) {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector=@selector(presentViewController:animated:completion:);
SEL swizzledSelector=@selector(my_presentViewController:animated:completion:);
Method originalMethod=class_getInstanceMethod(class,originalSelector);
Method swizzledMethod=class_getInstanceMethod(class,swizzledSelector);
BOOL didAddMethod = class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if(didAddMethod){
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
}else{
method_exchangeImplementations(originalMethod,swizzledMethod);
}
});
}
}
-(void)my_presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^ __nullable)(void))completion{
viewControllerToPresent.modalPresentationStyle = UIModalPresentationFullScreen;
[self my_presentViewController:viewControllerToPresent animated:YES completion:nil];
}
不用到处去为viewcontroller添加modalPresentationStyle = UIModalPresentationFullScreen
,如果你的viewcontroller是继承某个基类,也可直接在父类里init的时候添加modalPresentationStyle = UIModalPresentationFullScreen
网友评论