問題描述
我有一個(gè) UIScrollView
,它有一系列快速更新數(shù)字的標(biāo)簽(每 0.06 秒).然而,當(dāng)滾動(dòng)視圖移動(dòng)時(shí),NSTimer
會(huì)暫停,直到滾動(dòng)和彈性動(dòng)畫完成后才會(huì)繼續(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
運(yùn)行而不管滾動(dòng)視圖的狀態(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];
要從所有安裝了計(jì)時(shí)器的運(yùn)行循環(huán)模式中刪除計(jì)時(shí)器,請(qǐng)向計(jì)時(shí)器發(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 在滾動(dòng)時(shí)暫停 NSTimer的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!