如何解决UITextView为什么会闪烁?
我有一个UITextView
,当我执行textView.attributedText = ...
时,它有一定的闪烁可能性。我不知道是什么原因引起的,但是我有一些线索:
let oldOffset = textView.contentOffset
textView.attributedText = ...
// If it is not delayed,the modification will not take effect
dispatchQueue.main.asyncAfter(deadline: .Now() + 0.01) {
textView.contentOffset = oldOffset
}
下面是我创建UITextView
的代码:
public override init(frame: CGRect,textContainer: NSTextContainer? = nil) {
super.init(frame: frame,textContainer: textContainer)
config()
}
func config() {
textContainerInset = UIEdgeInsets(
top: 0,left: 10,bottom: 0,right: 10
)
delaysContenttouches = false
canCancelContenttouches = true
translatesAutoresizingMaskIntoConstraints = false
backgroundColor = .clear
textAlignment = .left
isEditable = false
showsverticalScrollIndicator = false
showsHorizontalScrollIndicator = false
scrollsToTop = false
isScrollEnabled = false
bounces = false
textContainer.lineFragmentPadding = 0
layoutManager.allowsNonContiguousLayout = false
}
我怀疑这两个原因之一是造成闪烁问题的原因,但不能排除其他原因。
如果有人可以帮助我,将不胜感激!
补充:我的UITextView
嵌套在UIScrollView
中,并使用自动版式。如有必要,请留言,我将添加相关代码
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。