【发布时间】:2016-09-03 18:04:29
【问题描述】:
我正在使用以下代码动态调整包含我的UITextView 的containerView 的高度
func textViewDidChange(textView: UITextView) {
let amountOfLinesToBeShown:CGFloat = 6
let maxHeight:CGFloat = textView.font!.lineHeight * amountOfLinesToBeShown
if ((textView.contentSize.height / textView.font!.lineHeight) < 6) {
topConstraint?.constant = -textView.sizeThatFits(CGSizeMake(textView.frame.size.width, maxHeight)).height - keyboardFrameSize!.height
containerView.layoutIfNeeded()
containerView.updateConstraints()
}
}
想要的效果是这样的:
【问题讨论】:
标签: ios swift uitextview nslayoutconstraint uitextviewdelegate