Here is what I am currently using for my inputAccessoryView.
I have a toolbar that contains a UITextView and send button and listens for textViewDidChange events as follows:
func textViewDidChange(_ textView: UITextView) {
let oldHeight = textView.height
let maxHeight: CGFloat = 100.0
var newHeight = min(textView.sizeThatFits(CGSize(width: textView.frame.width, height: CGFloat.greatestFiniteMagnitude)).height, maxHeight)
newHeight = ceil(newHeight)
if newHeight != oldHeight {
textView.frame.size.height = max(newHeight, barHeight)
updateHeight(height: newHeight)
}
}
- textView.
public func updateToolBarHeight(height: CGFloat) {
for constraint in constraints {
if constraint.firstAttribute == NSLayoutAttribute.height && constraint.firstItem as! NSObject == self {
constraint.constant = max(barHeight, height)
}
}
setNeedsUpdateConstraints()
sendButton.origin.y = max(0, height - barHeight)
}
barHeight - ( 50.0).
sendButton, .