UITextView自动滚动的解决方案
来源:互联网 发布:域名查询ip 编辑:程序博客网 时间:2024/04/27 13:56
思路:UIView加载完成3后,用NSTimer结合setContentOffset将UITextView向下滚动1像素。在滚动到底部的时候停止NSTimer。每当手动滚动UITextView前销毁NSTimer,滚动后重新创建NSTimer。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
NSTimer
*timer;
- (
void
)viewDidLoad {
[
self
performSelector:
@selector
(resetText) withObject:
nil
afterDelay:3.0f];
}
- (
void
)resetText {
[timer invalidate];
timer =
nil
;
timer = [
NSTimer
scheduledTimerWithTimeInterval: 0.06
target:
self
selector:
@selector
(onTick:)
userInfo:
nil
repeats:
YES
];
}
- (
void
)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[timer invalidate];
timer =
nil
;
NSLog
(@
"scrollViewWillBeginDragging"
);
[
self
performSelector:
@selector
(resetText) withObject:
nil
afterDelay:3.0f];
}
- (
void
) onTick:(
NSTimer
*)theTimer {
CGPoint pt = [textView contentOffset];
CGFloat n = pt.y + 1;
[textView setContentOffset:CGPointMake(pt.x, n)];
if
(n> (textView.contentSize.height-textView.bounds.size.height)) {
[theTimer invalidate];
theTimer =
nil
;
[timer invalidate];
timer =
nil
;
}
}
最后 不要忘了实现
UIScrollViewDelegate
- UITextView自动滚动的解决方案
- UITextView自动滚动的解决方案
- UIScrollView,UITableView,UITextView自动滚动代码分析
- UITextView 取消换行 文字自动向右滚动
- 让uitextview自动滚到最后一行并滚动减速
- UITextView内容添加后,自动滚动到最后一行
- iOS UITextView内容添加后,自动滚动到最后一行
- iOS UITextView内容添加后,自动滚动到最后一行
- UITextView内容添加后,自动滚动到最后一行
- iOS UITextView内容添加后,自动滚动到最后一行
- UITextView修改能容 自动滚动到最后一行
- IOS键盘挡住UITextView的解决方案
- 自动调整UITextView/UILabel的高度height
- 【iOS】UITextView 自动跳动的问题
- UITextView滚动到顶部
- CEdit的自动滚动
- 自动滚动的公告栏
- 自动滚动的TextView
- 一个网站通用的FLASH 图片切换特效!
- eclipse中的JVM理解
- php中序列化与反序列化
- No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active&
- python argparse使用示例
- UITextView自动滚动的解决方案
- Rhel磁盘管理
- ZigBee组网
- ios转义url中特殊符号与简单的 js 例子
- oracle常用函数详解(详细)
- 使用PDB进行Python调试
- 创建基于模板的小部件(Widget)
- error LNK2005: _DllMain@12 已经在 MSVCRTD.lib(dllmain.obj) 中定义
- java阶乘计算