Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Force iOS <13 modal behaviour in iOS 13 apps
@import UIKit;
NS_ASSUME_NONNULL_BEGIN
@interface UIViewController (iOS13)
@end
NS_ASSUME_NONNULL_END
#import "UIViewController+iOS13.h"
@import ObjectiveC.runtime;
@implementation UIViewController (iOS13)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(modalPresentationStyle);
SEL swizzledSelector = @selector(custom_modalPresentationStyle);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
method_exchangeImplementations(originalMethod, swizzledMethod);
});
}
- (UIModalPresentationStyle)custom_modalPresentationStyle {
if (@available(iOS 13.0, *)) {
UIModalPresentationStyle style = [[self valueForKey:@"_modalPresentationStyle"] integerValue];
return style == UIModalPresentationAutomatic ?
UIModalPresentationFullScreen :
style;
}
return [self custom_modalPresentationStyle];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.