iPhone自动滚动UITextView,但也允许手动滚动 [英] iPhone Auto-scroll UITextView but allow manual scrolling also

查看:364
本文介绍了iPhone自动滚动UITextView,但也允许手动滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含大量内容的UITextView。我有一个按钮,允许UITextView在NSTimer循环中自动滚动+10像素:

I have a UITextView that has a lot of content. I have a button that allows the UITextView to automatically scroll + 10 pixels in an NSTimer loop:

scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 10);
[textView setContentOffset:scrollPoint animated:YES];   

这很有效,因为动画使滚动相当平滑。我希望允许用户通过用手指滚动来向前或向后跳过,但是由于滚动动画后的代码,滚动会快速回到自动滚动的位置。

This works really well, as the animation makes the scroll rather smooth. I want to allow the user to skip ahead or back by scrolling with their finger, however due to this code after the scroll animation, the scroll snaps back to where it would have auto-scrolled.

我需要在手动滚动后重置scrollPoint变量,但我不知道该怎么做。我已经尝试实现委托方法

I need to reset the scrollPoint variable after a manual scroll, but I'm not sure how to do that. I've tried implementing the delegate method

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView;

但这种方法也会触发我的自动滚动。

but this method fires on my automatic scroll as well.

任何想法?

推荐答案

你可以让它相对于它的位置移动:

You could just make it move relative to where it is:

scrollPoint = textView.contentOffset;
scrollPoint.y= scrollPoint.y+10;
[textView setContentOffset:scrollPoint animated:YES];

这篇关于iPhone自动滚动UITextView,但也允许手动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆