iphone - 如何在 UITextView 中启用平滑滚动?

标签 iphone objective-c 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];
}

如何实现平滑滚动?谢谢

最佳答案

您可以使用动画 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/

相关文章:

iphone - 如何将图像从我们的应用程序导出到 Instagram?

ios7 - 为什么 UITextView 在我开始输入时垂直居中

ios - 替换 UITextView 的部分属性文本

objective-c - 如何使用日期和子字符串优化sqlite查询?

objective-c - 撤消/重做菜单项从未启用

ios - 在 NSManagedObject 上调用 MR_createEntity 时出错

ios - 将 UITextView 滚动到特定文本

iphone - MPMoviePlayerController 停止 iPod 音乐播放

iphone - 切换到基础国际化

iphone - Documents 目录中图像的图像缓存