UITextView poor content bias after animated viewing

I have one UITextView that is at the bottom. When the user clicks on it, I need to animate the view 150 pixels up. I use:

- (void)textViewDidBeginEditing:(UITextView *)textView{ 

and

 - (void)textViewDidEndEditing:(UITextView *)textView{ 

to do this.

On iOS5, it works fine. But on iOS 4.3, when the view is animated, the content in this UITextView has a few pixels up.

Screenshot: http://cl.ly/1q3e0W2G1M000u1U3w1f

Has anyone had similar problems?

Code:

 - (void)textViewDidBeginEditing:(UITextView *)textView{ if([textView.text isEqualToString:@"Placeholder text"]){ textView.text = @""; } [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDelegate:self]; [UIView setAnimationDuration:0.3]; [UIView setAnimationBeginsFromCurrentState:YES]; self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y - 150.0), self.view.frame.size.width, self.view.frame.size.height); [UIView commitAnimations]; } - (void)textViewDidEndEditing:(UITextView *)textView{ if([textView.text isEqualToString:@""]){ textView.text = @"Placeholder text"; } [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDelegate:self]; [UIView setAnimationDuration:0.3]; [UIView setAnimationBeginsFromCurrentState:YES]; self.view.frame = CGRectMake(self.view.frame.origin.x, (self.view.frame.origin.y + 150.0), self.view.frame.size.width, self.view.frame.size.height); [UIView commitAnimations]; } 
+4
source share
3 answers

You need to reset pasting the contents of your text view when calling the method in the textViewDidBeginEditing method and after the animation finishes ...

Try this code:

 - (void)textViewDidBeginEditing:(UITextView *)textView{ [textView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)]; } 
+4
source

I found that the accepted answer caused some visual disturbances. The following worked much better for me.

 textView.contentMode = UIViewContentModeTop; 
+3
source

Try UITextField to solve this problem.

-3
source

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


All Articles