前端 objective-c 定时器 nstimer 使用

yueliangdao0608 · June 08, 2020 · 8 hits

NSTimer 有一个属性叫 fireDate ,意思就是开始时间。所以我们设置一个超远的时间就是暂停,设置当前时间就是开始。

创建

1
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(testTimer) userInfo:nil repeats:YES];

暂停

1
[_timer setFireDate:[NSDate distantFuture]];

继续

1
[_timer setFireDate:[NSDate date]];

停止

1
[_time invalidate];

/* * * CONFIGURATION VARIABLES * * */ var disqus_shortname = 'lecason'; /* * * DON'T EDIT BELOW THIS LINE * * */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })(); Please enable JavaScript to view the comments powered by Disqus.
No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.