0

My UISrollView has subviews which include a textview, following by a uilabel, followed by an imageview.

The textview expands downwards, and has its own scrolling disabled.

I have a method which detects when the textview gets a new line, and it is supposed to expand the height of the textView, which it does

CGRect frame = _textView.frame;
frame.size.height = height + 10.0; //Give it some padding
_textView.frame = frame;

[self layoutIfNeeded];

the problem arises where the other elements positioned below the textview do not also expand downwards.

I've tried re-adding my constraints to those additional subviews, before the [self layoutIfNeeded] method, but nothing happens visually.

If you look at the Twitter 'new tweet' functionality on iOS, you will see a textView, followed by an imageView, and the textview expands when you type, and everything is pushed down, this is also in a scrollview. I am trying to create similar functionality but running into issues.

How do I fix my problem, since my solution is ineffective? Any insight appreciated

CQM
  • 42,592
  • 75
  • 224
  • 366
  • I think you might need to update the height constraint on the textFrame rather than set the frame. – Good Doug Jan 21 '16 at 23:06
  • @GoodDoug it appears that there are circumstances where my scrollview doesn't allow scrolling far enough, if my textview expands so far. I assumed it would expand in a way I expected, but do I need to manually expand the scrollview's height constraint too!? – CQM Jan 22 '16 at 20:32
  • 1
    you need to make sure the scrollview knows that it needs to updateConstraints – Good Doug Jan 24 '16 at 18:36
  • @GoodDoug I added `[_scrollView updateConstraints];` right after I increase the size of my textview, to no avail – CQM Jan 25 '16 at 15:00

0 Answers0