UITextView内容大小在iOS 8中没有增加

时间:2017-01-23 06:05:11

标签: ios swift ios8 uitextview

我创建了一个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()
}

0 个答案:

没有答案