我已经花了几天时间解决这个问题。
我有一个inputAccessoryView
由一个UIView
包含一个textView
和两个按钮组成的。的行为与inputAccessoryView
预期的一样,并且在除一种情况外的所有情况下都可以正常工作。
当 textView 的高度增加时,我试图将高度增加inputAccessoryView
相同的量。当我重新定义 in 的高度时,inputAccessoryView
在textViewDidChange
键盘inputAccessoryView
上方而不是向上增加高度。
我尝试了 SO 的许多不同建议,但没有任何效果。我想这是自动添加NSLayoutConstraint
的,inputAccessoryView
但我不知道如何在 swift 和 iOS 8.3 中更改该值。
func textViewDidChange(textView: UITextView) {
var contentSize = messageTextView.sizeThatFits(CGSizeMake(messageTextView.frame.size.width, CGFloat.max))
inputAccessoryView.frame.size.height = contentSize.height + 16
}
添加
inputAccessoryView.setTranslatesAutoresizingMaskIntoConstraints(true)
对上面的代码有帮助,并且 inputAccessoryView 的高度正确地向上增加,但是我无法同时满足多个约束的约束,并且很难识别违规者。此外,我还得到了一个奇怪的效果,即 textView 在每第二个新行实例的下方创建额外的空间。
谢谢。