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 但也允许手动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)