升級(jí)iOS13滤港,發(fā)現(xiàn)present模式modalPresentationStyle
發(fā)生了改變,原來(lái)是全屏.fullScreen
現(xiàn)在新加了.automatic
,但手機(jī)實(shí)測(cè)發(fā)現(xiàn)模式為.pageSheet
找到了比較方便的全局修改方法看到了,直接上代碼:
//MARK: - swizzlePresent
extension UIViewController{
//主要作用是適配ios13委乌,將present變?yōu)槿? static func swizzlePresent() {
let orginalSelector = #selector(present(_: 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
private func swizzledPresent(_ viewControllerToPresent: UIViewController,
animated flag: Bool,
completion: (() -> Void)? = nil) {
if #available(iOS 13.0, *) {
if viewControllerToPresent.modalPresentationStyle == .automatic || viewControllerToPresent.modalPresentationStyle == .pageSheet{
viewControllerToPresent.modalPresentationStyle = .fullScreen
}
}
swizzledPresent(viewControllerToPresent, animated: flag, completion: completion)
}
}
在AppDelegate里面調(diào)用一下就好了
UIViewController.swizzlePresent()