MKImpulse
是一个用于替换系统NSTimer
的高精度脉冲器
系统的NSTimer
被添加到Runloop
中,系统繁忙时会造成偏差,时间越长,偏差越大
而MKImpulse是基于GCD编写的脉冲器,精度由CPU时钟计算,误差可以平稳地控制在千分之一秒内
使用CocoaPods进行安装(1.0.0及以后的版本)
source 'https://github.com/CocoaPods/Specs.git'
target 'your project name' do
pod 'MKImpulse'
end
使用CocoaPods进行安装(1.0.0之前的版本)
pod 'MKImpulse'
从终端下载仓库
$git clone https://github.com/SYFH/MKImpulse.git
回调式
#import "MKImpulseManager.h"
[[MKImpulseManager defaultManager] impulseWithRepeat:3 action:^{
NSLog(@"action_2:%@", [NSThread currentThread]);
}];
目标-响应式
#import "MKImpulseManager.h"
[[MKImpulseManager defaultManager] impulseWithRepeat:10 target:self selector:@selector(testMethod)];
自定脉冲间隔,开始时间,脉冲间隔,脉冲精度,执行线程
[[MKImpulseManager defaultManager] impulseWithQueue:IMPULSE_GLOBAL_QUEUE
repeat:5
start:1
interval:2
accuracy:0
action:^{
NSLog(@"你要执行的任务");
}];
[[MKImpulseManager defaultManager] impulseWithQueue:IMPULSE_GLOBAL_QUEUE
repeat:IMPULSE_UNLIMITED
start:1
interval:2
accuracy:0
target:self
selector:@selector(testMethod)];