iPhone Auto-scroll UITextView but allow manual scrolling also(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 但也允许手动滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iPhone 自动滚动 UITextView 但也允许手动滚动
基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01