调整 accessoryInputView 的大小?

Resizing accessoryInputView?

我已经尝试调整 UITextField 的大小但失败了,它位于 UIView 中,它被设置为该文本字段的 inputAccessoryView

现在我一直在尝试调整大小。当用户输入 2 行或更多行的文本时,文本字段应调整大小,周围视图也应调整大小 (inputAccessoryView)。

我的 UITextFieldDelegate 中有以下代码:

func textViewDidChange(textView: UITextView) {
    println("textViewDidChange called")
    sendButton.enabled = textView.hasText()
    var oldHeight = textView.frame.height
    var textWidth = textView.frame.width
    textView.sizeToFit()

    var textFrame = textView.frame
    textFrame.size.height = textView.contentSize.height
    textFrame.size.width = textWidth
    textView.frame = textFrame
    var newHeight = textView.frame.height

    moveToolbarUp(newHeight - oldHeight)
    self.frame.size.height += newHeight - oldHeight
    self.superview?.updateConstraints()
}

现在,当我在文本字段中键入过多内容时,会出现 this。我怎样才能确保这不会发生?此外,当我按下 return 键时,完整的 inputAccessoryView 会重置。我应该在 delegate 中使用其他方法吗?我不应该自己计算这些高度吗?为什么我的 inputAccessoryView 不能正确调整大小,而只有我的 textView?

因为我使用的是 Autolayout,所以我应该使用它...它通过在 UITextField 上设置高度约束来工作,然后我通过这些计算更改它...