Large font UITextView text disappears when setting setContentOffset with animation

I read the entire existing solution in stackoverflow for similar problems, but without it.

Malfunction in UITextView when trying to scroll text to position with animation. The upper part of the text disappears when scrolling with animation, but if the font size is 15pt everything is fine, but if it is about 50pt, then something will go wrong.

You can see it on the video https://www.youtube.com/watch?v=EvIur672Q5k

I am also trying to create my own method to animate scrolling with a loop and offset the offset of each loop by 0.5pt, but this uses the processor too much, and I cannot control the animation time because the processor is overloaded. https://www.youtube.com/watch?v=Kw5hx3YAdMw

I am also trying to create a UITextView programmatically with the same result.

I am trying to split the animation into parts with a linear curve, but this is such an ugly shake animation.

- (IBAction) start{

    _textView.scrollEnabled = NO;
    _textView.scrollEnabled = YES;


    UITextPosition *Pos2 = [_textView positionFromPosition: _textView.beginningOfDocument offset: 501];
    UITextPosition *Pos1 = [_textView positionFromPosition: _textView.beginningOfDocument offset: 500];
    UITextRange *range = [_textView textRangeFromPosition:Pos1 toPosition:Pos2];

    CGRect result1 = [_textView firstRectForRange:(UITextRange *)range];

    result1.origin.x=0;
    [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
           _textView.contentOffset = result1.origin;
     } completion:^(BOOL finished){
     }];     
}
+6
source share
2 answers

I believe that you are trying to do it

- (IBAction)start:(id)sender {
   _textView.scrollEnabled = NO;
   _textView.scrollEnabled = YES;

   NSRange bottom = NSMakeRange(_textView.text.length, 0);
  [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
    [_textView scrollRangeToVisible:bottom];
  } completion:nil];
}

This should make the text length range and scroll to the end. If I misunderstood your problem, please let me know and I will do my best to help.

+1
source

I think this is not what you want, but look here . You may have found a solution.

+1
source

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


All Articles