There are a number of methods to try this, and I believe every one might match for one venture however not one other, so I assumed I will hold them right here possibly another person will run to a special case.
1- Override current
When you’ve got a BaseViewController you possibly can override the current(_ viewControllerToPresent: animated flag: completion:) technique.
class BaseViewController: UIViewController {
// ….
override func current(_ viewControllerToPresent: UIViewController,
animated flag: Bool,
completion: (() -> Void)? = nil) {
viewControllerToPresent.modalPresentationStyle = .fullScreen
tremendous.current(viewControllerToPresent, animated: flag, completion: completion)
}
// ….
}
Utilizing this fashion you need not do any change on any current name, as we simply overrode the current technique.
2- An extension:
extension UIViewController {
func presentInFullScreen(_ viewController: UIViewController,
animated: Bool,
completion: (() -> Void)? = nil) {
viewController.modalPresentationStyle = .fullScreen
current(viewController, animated: animated, completion: completion)
}
}
Utilization:
presentInFullScreen(viewController, animated: true)
3- For one UIViewController
let viewController = UIViewController()
viewController.modalPresentationStyle = .fullScreen
current(viewController, animated: true, completion: nil)
4- From Storyboard
Choose a segue and set the presentation to FullScreen.
5- Swizzling
extension UIViewController {
static func swizzlePresent() {
let orginalSelector = #selector(current(_: animated: completion:))
let swizzledSelector = #selector(swizzledPresent)
guard let orginalMethod = class_getInstanceMethod(self, orginalSelector), let swizzledMethod = class_getInstanceMethod(self, swizzledSelector) else{return}
let didAddMethod = class_addMethod(self,
orginalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod))
if didAddMethod {
class_replaceMethod(self,
swizzledSelector,
method_getImplementation(orginalMethod),
method_getTypeEncoding(orginalMethod))
} else {
method_exchangeImplementations(orginalMethod, swizzledMethod)
}
}
@objc
personal func swizzledPresent(_ viewControllerToPresent: UIViewController,
animated flag: Bool,
completion: (() -> Void)? = nil) {
if #accessible(iOS 13.0, *) {
if viewControllerToPresent.modalPresentationStyle == .automated {
viewControllerToPresent.modalPresentationStyle = .fullScreen
}
}
swizzledPresent(viewControllerToPresent, animated: flag, completion: completion)
}
}
Utilization:In your AppDelegate inside utility(_ utility: didFinishLaunchingWithOptions) add this line:
UIViewController.swizzlePresent()
Utilizing this fashion you need not do any change on any current name, as we’re changing the current technique implementation in runtime.If it’s good to know what’s swizzling you possibly can verify this hyperlink:
https://nshipster.com/swift-objc-runtime/