Frage

I'm using this code to make a dynamic UITextView with auto resize

- (void)textViewDidChange:(UITextView *)txtView
{
    CGRect frame;
    frame = txtView.frame;
    frame.size.height = [textView contentSize].height;
    textView.frame = frame;
}

the code is fine, but when i press "return" in the keyboard (break line), I need the textView to grow UP direction and not down like it is now.

I tried to do something with the "CGRectGetMaxY(textView.frame)" becuase I know that the bottom of the textView need to stay as it is and not change, but I didn't find the right way.

This textView using for a chat message output, so if the user writing something long, the textView need to grow up becuase the keyboard is bellow

War es hilfreich?

Lösung

This should do the trick:

- (void)textViewDidChange:(UITextView *)textView
{
    CGRect frame = textView.frame;
    frame.origin.y = CGRectGetMaxY(frame) - [textView contentSize].height;
    frame.size.height = [textView contentSize].height;
    textView.frame = frame;
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top