Transition on initial setup of UITextView frame size in UIView animation

I have the following code to expand a text area and view it whenever a user clicks on a field and editing starts:

- (void)textViewDidBeginEditing:(UITextView *)textView { textView.text = @""; CGRect titleViewFrame = self.titleLabel.frame; titleViewFrame.size.height = kExpandedSubviewFrameHeight; CGRect titleTextViewFrame = self.titleTextView.frame; titleTextViewFrame.size.height = kExpandedSubviewFrameHeight; [UIView animateWithDuration:0.4f animations:^{ self.titleLabel.frame = titleViewFrame; self.titleTextView.frame = titleTextViewFrame; }]; } 

Everything works fine, except that the user first removes this field, and the origin of the text view goes into bit:

enter image description here

Any help is greatly appreciated.

+4
source share
1 answer

A bit late, but I had the same problem when resizing a uitextview and I think this is due to scrolling text view. This is my code that has 0 failures when animating height. I am using NSLayoutConstraint to adapt my height.

 - (void)textViewDidChange:(UITextView *)textView { CGSize size = [messageView sizeThatFits:CGSizeMake(messageView.frame.size.width, FLT_MAX)]; [UIView animateWithDuration:0.4f animations:^{ messageHeightConstraint.constant = size.height; [self.view layoutIfNeeded]; } completion:^(BOOL finished) { [messageView scrollRangeToVisible:NSMakeRange([messageView.text length], 0)]; } ]; } 
+1
source

Source: https://habr.com/ru/post/1496919/


All Articles