我创建了一个UITextView并将isScrollEnabled
设置为true,在textView中粘贴两行文本后,我按键盘输入文本,但textView' s contentSize
没有增加,它只发生在iOS 8中,只有在我粘贴两行文字后才会发生。
func textViewDidChange(_ textView: UITextView) {
if textView.text.isEmpty {
updateCommentViewHeight(45.0)
} else {
let height = calculateTextSize(with: textView).height //calulate textview height by content text
updateCommentViewHeight(height + 30.0)
if commentInputView.bounds.height > height + 29.0 {
textView.isScrollEnabled = true
} else {
textView.isScrollEnabled = false
}
}
}
private func updateCommentViewHeight(_ height: CGFloat) {
constrain(commentInputView, replace: group, block: { (commentInputView) in
commentInputView.height == height
})
view.layoutIfNeeded()
}