我有一个包含很多内容的 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 但也允许手动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!