7

I read all exists solution on stackoverflow for similar trouble but without lack.

Trouble in UITextView when i try scroll text to position with animation. Top part of text disappear when scroll with animation, but if font size 15pt all is ok but if around 50pt then something goes wrong.

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

I also try create my own method to animate scroll with loop and each loop move offset on 0.5pt it works but this utilised processor too much, and i cannot control animation time, because processor overloaded. https://www.youtube.com/watch?v=Kw5hx3YAdMw

I also try create UITextView programmatically with same result.

I try split animation on parts with linear curve but it so ugly animation with shake.

- (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){
     }];     
}
Dmitriy Pushkarev
  • 390
  • 2
  • 5
  • 26
  • 1
    did you try to use a `UILabel` inside a `UIScrollView` and animate `UIScrollView`? if your `UITextView` is not editable, that may solve your problem – Mert Buran Apr 11 '17 at 17:16
  • Thank you Mert. It's simple good idea but my scrolling based on position in text. My app scrolling use firstRectForRange which return x y(i need only y) coordinate for specific text position. it's not compatible method for UILabel, now i try to find solution with UILabel. Thank you for your idea. – Dmitriy Pushkarev Apr 12 '17 at 01:15

1 Answers1

1

I believe you're trying to do this

- (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 a range of the text length and scroll to the bottom of it for you. If I have misunderstood your problem please let me know and I'll do my best to help

HarmVanRisk
  • 203
  • 1
  • 8
  • 1
    Thank you for your response. But this not work correctly because animateWithDuration not works with scrollRangeToVisible, i mean cannot control speed of scrolling – Dmitriy Pushkarev Apr 07 '17 at 20:57