iPhone 自动滚动 UITextView 但也允许手动滚动

iPhone Auto-scroll UITextView but allow manual scrolling also(iPhone 自动滚动 UITextView 但也允许手动滚动)
本文介绍了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 但也允许手动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
How to Cancel Scrolling in UIScrollView(如何在 UIScrollView 中取消滚动)