uitextView contentsize在粘贴ios之后不更新
当我粘贴一些文本时,contententsize的文本视图高度不正确。它在粘贴之前返回文本高度。
例如,
我期望高度值:[contentsize height] 1019(粘贴后) 但是实际价值:[contentsize height] 540(粘贴之前)
我尝试了 setneeddisplay()方法,但它不起作用。
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool
{
print("[contentSize] \(textView.contentSize.height) size to fit \(textView.sizeThatFits(view.frame.size).height)")
}
When I paste some text, textview height of contentSize is not correct. It returns text height before paste.
For example,
I expect height value : [contentSize Height] 1019 (after paste)
But real value : [contentSize Height] 540 (before paste)
I tried setNeedDisplay() method, but it's not working.
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool
{
print("[contentSize] \(textView.contentSize.height) size to fit \(textView.sizeThatFits(view.frame.size).height)")
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当
textView(_:syredchangeTextin:替换text:)
被称为文本尚未应用于视图时,这意味着内容化尚未更改。如果可能的话,您可以使用textViewDidchange(_:)
,它应该打印正确的大小。如果您确实需要在
shordchangetextin
方法上计算文本的大小,则可以尝试使用这个。When
textView(_:shouldChangeTextIn:replacementText:)
is called the text hasn't been applied to the view yet which means the contentSize has not changed. If possible, you can usetextViewDidChange(_:)
, it should print the correct size.If you really need to calculate the size of the text on the
shouldChangeTextIn
method, you could try calculating the size using an approach like this.