modalPresentationStyleデフォルトUIModalPresentationAutomaticのiOS13は、修正するためには、あなたが手動で設定する必要がありますvc.modalPresentationStyle = UIModalPresentationFullScreen;
アニメーション:完了:しかし、各presentViewControllerに必要な変更は、このようなAコードを含める前には、複数のファイルを変更する必要があり、複数のコードページは、後にジャンプがありますまた、あなたは簡単にミスに、あまりにも面倒、そのような文を追加する必要があります。
私たちは、元のコードを変更せずに、次のような方法はあまりトラブルはなかった使用して、ページジャンプがあり、彼らはより多くのコードを払っていません。
私たちは、のUIViewControllerの分類を確立している、の.M分類に次のコードを追加します
+ (void)load {
// 方法交换,为的是当系统调用viewDidLoad时候,调用的是我们的my_viewDidLoad方法
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(viewDidLoad);
SEL swizzledSelector = @selector(my_viewDidLoad);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL success = class_addMethod(class, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod));
if (success) {
class_replaceMethod(class, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
- (void)my_viewDidLoad {
[self my_viewDidLoad]; // 由于方法交换,实际上调用的是系统的viewDidLoad
NSArray *viewcontrollers=self.navigationController.viewControllers;
if (viewcontrollers.count > 1) {
} else {
//present方式
self.modalPresentationStyle = UIModalPresentationFullScreen; // 修改默认值
}
}
どのように使用するには:
UIViewController *vc = [[UIViewController alloc] init];
[self presentViewController:vc animated:YES completion:nil]; // 即使是在iOS13下vc也是全屏显示
modalPresentationStyleの値を変更します。
UIViewController *vc = [[UIViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:vc animated:YES completion:nil]; // 不管是在iOS13还是之前版本,都是以UIModalPresentationPopover模式