gpt4 book ai didi

ios - DTAttributedTextView 不重新布局

转载 作者:行者123 更新时间:2023-11-30 13:55:23 25 4
gpt4 key购买 nike

当 DTAttributedTextView 的框架更改时, View 内的内容(文本)不会重新布局。我的 tableView 单元格中有 TextView ,其高度由布局约束指定,我在代码中更改了该值。宽度会根据单元格宽度的约束自动变化。

我尝试手动调用setNeedsLayoutlayoutIfNeededrelayoutTextsetNeedsDisplay。似乎没有什么帮助。为什么内容布局会这样锁定?

这似乎适用于高度,但不适用于宽度:

override func layoutSubviews() {
super.layoutSubviews()

comment.attributedTextContentView.layoutFrame = DTCoreTextLayoutFrame(
frame: comment.frame,
layouter: comment.attributedTextContentView.layouter)
comment.relayoutText()
}

最佳答案

调用relayoutText之前需要将layouter设置为nil

comment.attributedTextContentView.layoutFrame = DTCoreTextLayoutFrame(
frame: comment.frame,
layouter: comment.attributedTextContentView.layouter)
//gets rid of cached layouter
comment.layouter = nil
comment.relayoutText()

关于ios - DTAttributedTextView 不重新布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33691992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com