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];
}
如何实现平滑滚动?谢谢
最佳答案
您可以使用动画 NO 使该技巧逐像素滚动,因为它在完成滚动后不会像动画 YES 属性那样停止。你唯一需要设置的是velocityFactor作为你的NSTimer应该被调用的时间,而不是滚动应该移动。滚动完成 contentSize 后,使计时器无效,滚动应该停止。
- (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];
}
}
关于iphone - 如何在 UITextView 中启用平滑滚动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7349847/