查看modalPresentationStyle属性,你会发现
/*
Defines the presentation style that will be used for this view controller when it is presented modally. Set this property on the view controller to be presented, not the presenter.
If this property has been set to UIModalPresentationAutomatic, reading it will always return a concrete presentation style. By default UIViewController resolves UIModalPresentationAutomatic to UIModalPresentationPageSheet, but system-provided subclasses may resolve UIModalPresentationAutomatic to other concrete presentation styles. Participation in the resolution of UIModalPresentationAutomatic is reserved for system-provided view controllers.
Defaults to UIModalPresentationAutomatic on iOS starting in iOS 13.0, and UIModalPresentationFullScreen on previous versions. Defaults to UIModalPresentationFullScreen on all other platforms.
*/
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle API_AVAILABLE(ios(3.2));
重点是如下这句,意为从iOS13.0开始,该属性默认值是UIModalPresentationAutomatic,之前版本默认值仍然是UIModalPresentationFullScreen
Defaults to UIModalPresentationAutomatic on iOS starting in iOS 13.0, and UIModalPresentationFullScreen on previous versions. Defaults to UIModalPresentationFullScreen on all other platforms.
如果我们通过模态弹出的控制器仍然需要全屏显示:
- 可以直接找到相应位置直接修改
如果你的项目里存在较多模态弹出页面 这么修改起来会比较麻烦,也很容易遗漏
if (@available(iOS 13.0, *)) {
vc = UIModalPresentationFullScreen;
}
- 使用runtime交换方法
该方法好处就是在不侵入原先代码的情况下 做到全部修改
- 新建一个UIViewController的category(分类、类别、类目)
- 分类中#import <objc/runtime.h>
- 分类的load方法中
+ (void)load {
SEL oriSel = @selector(presentViewController:animated:completion:);
SEL overSel = @selector(ct_presentViewController:animated:completion:);
Method method1 = class_getInstanceMethod([self class], oriSel);
Method method2 = class_getInstanceMethod([self class], overSel);
method_exchangeImplementations(method1, method2);
}
- (void)ct_presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion {
if (@available(iOS 13.0, *)) {
viewControllerToPresent.modalPresentationStyle = UIModalPresentationFullScreen;
}
[self ct_presentViewController:viewControllerToPresent animated:flag completion:completion];
}
网友评论