对于Xcode 11.2,基于Aftab Muhammed Khan的想法,在John Nimis的帮助下,我测试了以下代码。
无需更改故事板文件!
编辑我的AppDelegate.swift文件并添加了这个类
//******************************************************************
// MARK: - Workaround for the Xcode 11.2 bug
//******************************************************************
class UITextViewWorkaround: NSObject {
// --------------------------------------------------------------------
// MARK: Singleton
// --------------------------------------------------------------------
// make it a singleton
static let unique = UITextViewWorkaround()
// --------------------------------------------------------------------
// MARK: executeWorkaround()
// --------------------------------------------------------------------
func executeWorkaround() {
if #available(iOS 13.2, *) {
NSLog("UITextViewWorkaround.unique.executeWorkaround(): we are on iOS 13.2+ no need for a workaround")
} else {
// name of the missing class stub
let className = "_UITextLayoutView"
// try to get the class
var cls = objc_getClass(className)
// check if class is available
if cls == nil {
// it's not available, so create a replacement and register it
cls = objc_allocateClassPair(UIView.self, className, 0)
objc_registerClassPair(cls as! AnyClass)
#if DEBUG
NSLog("UITextViewWorkaround.unique.executeWorkaround(): added \(className) dynamically")
#endif
}
}
}
}
并在委托中调用“didFinishLaunchingWithOptions”调用解决方案
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
// This is the workaround for Xcode 11.2
UITextViewWorkaround.unique.executeWorkaround()
}