我尝试过调整UITextField位于 a 内的a 的大小,但未能成功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()
}
现在,当我在文本字段中输入太多时,就会发生这种情况。我如何确保不会发生这种情况?inputAccessoryView此外,当我按回车键时,完全重置。我应该在中使用另一种方法delegate吗?我不应该自己计算这些高度吗?为什么我没有inputAccessoryView正确调整大小,而只有我的 textView?