I'm trying to make a text messaging text box that makes the text view bigger and the UIView (in which the text view is contained) bigger as well. I'm working with constraints. When I reach a certain height, I want it to scroll and stop increasing the heights of the container. I've tried all ways possible, including using this forum (How do I size a UITextView to its content?).
One problem occurs when I type it in, once I reach a certain height, it starts typing out of sight below.
func textViewDidChange(textView: UITextView) {
let fixedWidth = self.chatTextField.frame.size.width
self.chatTextField.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
let newSize = self.chatTextField.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
var newFrame = self.chatTextField.frame
newFrame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height)
print(textViewAnchorHeight?.constant)
if textView.contentSize.height <= self.chatTextFieldHeightAnchor?.constant {
textView.scrollEnabled = false
self.chatTextField.frame = newFrame
//self.chatTextFieldHeightAnchor?.constant = newSize.height
self.textViewAnchorHeight?.constant = newSize.height
} else {
textView.scrollEnabled = true
self.automaticallyAdjustsScrollViewInsets = true
print("here")
}
What can I do to make the perfect text view?