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 但也允许手动滚动


- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01