Open IAFung opened 3 years ago
我换电脑了 现在没有iOS11以下的环境, 能发一些详细的截图吗? 这个问题可以稳定复现吗?
稳定复现,使用kvo的keypath的方式在iOS11以下好像要手动调用invalidate释放 调用代码
class SXTextView: UITextView {
private let customLabel = UILabel()
@objc var string: String? {
didSet {
customLabel.text = "交易备注"
customLabel.font = .systemFont(ofSize: 12)
customLabel.backgroundColor = #colorLiteral(red: 0.9098039216, green: 0.2078431373, blue: 0.1333333333, alpha: 0.1004120291)
customLabel.textColor = #colorLiteral(red: 0.9098039216, green: 0.2078431373, blue: 0.1333333333, alpha: 1)
customLabel.textAlignment = .center
customLabel.frame = CGRect(x: 0, y: -3, width: 58, height: 23)
isEditable = false
isSelectable = false
attributed.text = .init("\(.view(customLabel, .original(.center))) \(string!)", .paragraph(.lineSpacing(7)))
attributed.layout()
}
}
@objc func layout() {
attributed.layout()
}
}
let textView = SXTextView()
textView.string = "qeqewqkqwkjrqwjrkjqjnsdnfajsnfieuwrhweirhiuweqweqwe"
view.addSubview(textView)
每次调用的页面释放时,崩溃信息如下:
2021-01-06 10:36:55.640 XibTest[14529:1236068] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x7ffa900ffe00 of class XibTest.SXTextView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x618000039c20> (
<NSKeyValueObservance 0x61800005a190: Observer: 0x618000059d40, Key path: bounds, Options: <New: YES, Old: YES, Prior: NO> Context: 0x0, Property: 0x618000059830>
<NSKeyValueObservance 0x61800005a4c0: Observer: 0x61800005a520, Key path: frame, Options: <New: YES, Old: YES, Prior: NO> Context: 0x0, Property: 0x61800005a580>
)'
你好, 还存在这个问题吗? 抱歉 过这么久才看到你的回复
在iOS11以下的系统,kvo的监听会崩溃,An instance 0x7f9395d49750 of class SXLabel was deallocated while key value observers were still registered with it. Current observation info: 使用了textView的attachment
attributed.text = .init("\(.view(customLabel, .original(.center))) \(string)", .paragraph(.lineSpacing(7)))