【发布时间】:2015-03-09 10:32:19
【问题描述】:
我尝试调整位于UIView 内的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 会发生。我如何确保不会发生这种情况?此外,当我按下返回键时,完整的inputAccessoryView 会重置。我应该在delegate 中使用另一种方法吗?我不应该自己计算这些高度吗?为什么我的inputAccessoryView 没有正确调整大小,而只有我的 textView?
【问题讨论】:
标签: ios resize inputaccessoryview