我正在尝试将此代码转换为Swift5。我收到2条错误消息:
'encodedOffset'已弃用:encodedOffset已弃用为 最常见的用法是不正确的。使用utf16Offset(in :)实现 相同的行为。
我该如何解决?
extension UITextView {
func frame(ofTextRange range: Range<String.Index>?) -> CGRect? {
guard let range = range else { return nil }
let length = range.upperBound.encodedOffset-range.lowerBound.encodedOffset
guard
let start = position(from: beginningOfDocument, offset: range.lowerBound.encodedOffset),
let end = position(from: start, offset: length),
let txtRange = textRange(from: start, to: end)
else { return nil }
let rect = self.firstRect(for: txtRange)
return self.convert(rect, to: textInputView)
}
}