iOS三种定时器
一、 NSTimer
注意点:timerWithTimeInterval: target: selector: userInfo: repeats:凡是timerWithTimeInterval开头的都是需要手动添加到RunLoop中。scheduledTimerWithTimeInterval开头的方法内部自动添加到RunLoop中。
//这里的self换成weakSelf 也不行,里面找到target的地址再强引用
NSTimer * timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(test) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode]

本文深入解析iOS中的三种定时器:NSTimer、CADisplayLink和dispatch_source_t。详细介绍了它们的工作原理、优缺点及使用场景。NSTimer适用于简单定时任务,但计时不够精确;CADisplayLink基于屏幕刷新率,提供更精准的定时;dispatch_source_t则提供了高精度定时,但需独立队列处理。
最低0.47元/天 解锁文章
892

被折叠的 条评论
为什么被折叠?



