I understand there are some similar posts but they don't seem to work for me.
I have a uitextview that I want to behave similar to messenging apps.
I used autolayouts and [textview setScrollEnabled:NO] to allow the uitextview to expand dynamically above the keyboard. Of course, it grows till it reaches the top of the screen. When it stops growing you cant see any additional text.
I tried to find the height where it stop growing inside the textViewDidChange and called [textView setScrollEnabled:YES], but it shrinked back the initial size before it grew.
How can i enable the scrolling when it reaches a certain height or cant grow anymore?
Best solution i've found till now was to leave scrolling enabled and changing textview's height according to it's content size.
Looks something like this:
- (void)textViewDidChange:(UITextView *)textView
{
self.consTextViewHeight.constant = MIN(MAX_HEIGHT, textView.contentSize.height + textView.textContainerInset.top);
}
Have you tried to setContentSize for textView? You can do that in viewDidLayoutSubviews if you want to wait for autolayout to finish.
Here is helpful link : how set content size of textView's Scrollview immediately when user starts scrolling or when tap on textview
NOTE: this should be a comment, but I don't have enough reputation for that...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With