日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS定时器

發(fā)布時間:2024/7/19 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS定时器 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

相關(guān)類:NSTimer

A timer is not a real-time mechanism; it fires only when one of the run loop modes to which the timer has been added is running and able to check if the timer’s firing time has passed. Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds. If a timer’s firing time occurs during a long callout or while the run loop is in a mode that is not monitoring the timer, the timer does not fire until the next time the run loop checks the timer.

Timer不是實(shí)時的,依賴于運(yùn)行的loop,精度為50-100ms。如果run loop沒有monitoring timer或者正在long callout,Timer不會被觸發(fā)。

創(chuàng)建定時器

A timer object can be registered in only one run loop at a time, although it can be added to multiple run loop modes within that run loop. There are three ways to create a timer:scheduledTimerWithTimeInterval、timerWithTimeInterval和initWithFireDate

后兩者在創(chuàng)建之后需要調(diào)用addTimer:forMode:

Once scheduled on a run loop, the timer fires at the specified interval until it is invalidated. A non-repeating timer invalidates itself immediately after it fires.you should always call the?invalidate?method from the same thread on which the timer was installed. Invalidating the timer immediately disables it so that it no longer affects the run loop.

?

NSTimer *timer?= [NSTimer?scheduledTimerWithTimeInterval:100?target:self?selector:@selector(timerFireMethod:)?userInfo:nil?repeats:YES];

userInfo:The user info for the timer. The timer maintains a strong reference to this object until it (the timer) is invalidated. This parameter may be?nil.

?

selector原型:?-(void)timerFireMethod:(NSTimer*)timer

啟停

暫停:[timer?setFireDate:[NSDate distantFuture]]

恢復(fù):[timer setFireDate:[NSDate date]]

轉(zhuǎn)載于:https://www.cnblogs.com/shanlilaideyu/p/4193621.html

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的iOS定时器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。