ibireme / YYText

Powerful text framework for iOS to display and edit rich text.
MIT License
8.85k stars 1.69k forks source link

scrollEnabled = false 后的高度计算 #478

Open Slience2015 opened 8 years ago

Slience2015 commented 8 years ago

YYTextView 设置(文本比较长)

 _textView.scrollEnabled = false; 

之后 ,计算高度

 CGSize size = CGSizeMake(gScreenWidth - 20, CGFLOAT_MAX);
 YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:size text:_textView.attributedText];
_textView.frame = CGRectMake(10, CGRectGetMaxY(_headerView.frame) + 5, gScreenWidth - 20, layout.textBoundingSize.height + 10);

计算出来的高度不准确 设置

_textView.scrollEnabled = true; 

就好了。这个是为什么呀?

ibireme commented 8 years ago

与这个应该完全没关系啊。。

YYTextView 由于需要多余换行符来显示光标,计算高度稍微麻烦些,推荐用 sizeThatFit 之类的直接调整;或者,先在字符串后面添加 "\r" 再计算。

Slience2015 commented 8 years ago

@ibireme 刚才试了sizeThatFit之类的直接调整,高度还是不对;在字符串后面添加 "\r" 再计算也一样

对了, 我是把textView当做了tableView的headerView,计算出高度之后设置为headerView的高度

用demo测试了一下,还是textView.scrollEnabled = true时计算正常,textView.scrollEnabled = false就不准确了

ibireme commented 8 years ago

这个就不清楚了,scrollEnabled 与内容和高度应该都没关系。。 如果还有问题就换成 YYLabel 吧。