gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:18:39 24 4
gpt4 key购买 nike

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com