常常在用 NSTimer 來設計一些延遲或重覆執行某個 func call,但如果有用到 touch 事件,如:圖片點擊,UIScrollView 滑動等,就會把該 fund call 暫停,直到 touch 結束才繼續執行。
這樣一來就有時間差的問題存在,問了 google 大大後得知有人分享解決方式,就是將 NSTimer 加到別的 RunLoopMode 即可。
在 NSTimer 初始化後加入以下指令:
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
參考來源:http://stackoverflow.com/questions/6684016/why-timer-stops-when-scrolling-in-uiwebview-iphone
沒有留言:
張貼留言