UITextView 坑

  • setAttributedText: 后,会自动滚动到文本中间的位置。

解决办法:

bottomTextView = UITextView()
bottomTextView.delegate = self
bottomTextView.backgroundColor = UIColor.clear
bottomTextView.isSelectable = true
bottomTextView.isEditable = false
bottomTextView.isUserInteractionEnabled = true
bottomTextView.linkTextAttributes = [:]
bottomTextView.attributedText = attributedString
// 使用主操作队列来确保恢复操作在“重置为0”之后发生
OperationQueue.main.addOperation {
    self.bottomTextView.setContentOffset(CGPoint.zero, animated: false)
}
view.addSubview(bottomTextView)

你可能感兴趣的:(UITextView 坑)