問題描述
我有一個 UIScrollView
,它有一系列快速更新數(shù)字的標(biāo)簽(每 0.06 秒).然而,當(dāng)滾動視圖移動時,NSTimer
會暫停,直到滾動和彈性動畫完成后才會繼續(xù).
I have a UIScrollView
that has a series of labels which are rapidly updating numbers (every .06 seconds). While the scroll view is moving, however, the NSTimer
is paused and does not continue until after the scrolling and the elastic animation have finished.
如何避免這種情況并讓 NSTimer
運行而不管滾動視圖的狀態(tài)如何?
How can I avoid this and have the NSTimer
run regardless of the state of the scroll view?
推薦答案
解決此問題的簡單方法是將 NSTimer
添加到 mainRunLoop
.
An easy way to fix this is adding your NSTimer
to the mainRunLoop
.
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
要從所有安裝了計時器的運行循環(huán)模式中刪除計時器,請向計時器發(fā)送 invalidate
消息.
To remove a timer from all run loop modes on which it is installed, send an invalidate
message to the timer.
這篇關(guān)于UIScrollView 在滾動時暫停 NSTimer的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!