开发者

How to enable smooth scrolling in UITextView?

开发者 https://www.devze.com 2023-04-03 08:25 出处:网络
I\'ve got my UITextView set up for scrolling like开发者_运维技巧 this, -(void)startAutoScroll { NSLog(@\"AutoScroll Started\");
I've got my UITextView set up for scrolling like开发者_运维技巧 this,

-(void)startAutoScroll
{
    NSLog(@"AutoScroll Started");
    if (scrollingTimer == nil) {
        scrollingTimer = [NSTimer scheduledTimerWithTimeInterval:(60.0/1000.0)
                                                          target:self
                                                        selector:@selector(autoscrollTimerFired:) 
                                                        userInfo:nil 
                                                         repeats:YES];
    }

}

- (void) autoscrollTimerFired:(NSTimer *)timer
{
    scrollPoint = self.completeText.contentOffset;
    scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + velocityFactor);
    [self.completeText setContentOffset:scrollPoint animated:NO];
}

How to enable smooth scrolling? thanks


You can make the trick scrolling pixel by pixel with animated NO since it doesn't stop like the animated YES property after its done scrolling. The only thing you gotta set is the velocityFactor as the time your NSTimer should be called, not the scroll should move. And after the scroll is done with the contentSize, invalidate the timer and the scroll should stop.

- (void) autoscrollTimerFired:(NSTimer *)timer {
    [self.completeText setContentOffset:CGPointMake(0, self.completeText.contentOffset.y + 1.0) animated:NO];
    if (self.completeText.contentOffset.y != self.completeText.contentSize.height - self.completeText.frame.size.height) {
        scrollingTimer = [NSTimer scheduledTimerWithTimeInterval:velocityFactor target:self selector:@selector(autoscrollTimerFired:) userInfo:nil repeats:NO];
    } else {
        [scrollingTimer invalidate];
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消