How to enable smooth scrolling in UITextView?
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];
}
}
精彩评论