我将 UITextView 放在 UIView 中。当用户在 UITextView 中键入时,UIView 会扩展,但问题是,如果用户在下一行键入,它不会显示正在键入的文本,直到用户在第三行键入,然后它会显示打印在第二行。第 3 行和第 4 行等也是如此。
我该如何解决这个问题?
func textViewDidChange(_ textView: UITextView) {
print(textView.text)
let size = CGSize(width: prayerRequest.frame.width, height: .infinity)
let estimatedSize = textView.sizeThatFits(size)
textView.constraints.forEach { (constraints) in
if constraints.firstAttribute == .height {
constraints.constant = estimatedSize.height
}
viewContainer.constraints.forEach({ (constraints) in
if constraints.firstAttribute == .height {
constraints.constant = estimatedSize.height
viewContainer.layoutIfNeeded()
}
})
}
}
最佳答案
如果您使用的是界面生成器,请尝试将行数设置为 0。
或者从代码 textView.textContainer.maximumNumberOfLines = 10
关于ios - UITextView 不在 nextLine 上打印文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56154486/