繁体   English   中英

将字符串粘贴到 uitextview 中的文本底部时会添加额外的空间

[英]Extra space is added at the bottom of text in uitextview when string is pasted into it

当我在UITextView粘贴文本时,会在其中添加一些额外的空间。 但是当我滚动它时,文本textView会根据内容进行安装。 textViewDidChange ,根据其内容大小设置textView高度约束。 有人遇到过同样的问题吗?

func textViewDidChange(_ textView: UITextView) {
    let newSize = textView.sizeThatFits(CGSize.init(width: textView.frame.size.width, height: CGFloat(MAXFLOAT)))
    textView.isScrollEnabled = false
    if newSize.height < 37 {
        self.messageTextViewHeightConstraint.constant = minimumTextviewHeight
    }
    if (newSize.height >= 37 && newSize.height <= 100) {
        self.messageTextViewHeightConstraint.constant = newSize.height
    }
    if (newSize.height >= 100) {
        self.messageTextViewHeightConstraint.constant = maximumTextviewHeight
        self.textView.isScrollEnabled = true
    }
}

您必须将 textView 的 smartInsertDeleteType 设置为 .no

textView.smartInsertDeleteType = .no

参考链接: https : //developer.apple.com/documentation/uikit/uitextinputtraits/2865828-smartinsertdeletetype

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM