1
以下是我在touchesMoved:withEvent:中使用的代碼。 定時器將用下面的代碼零星火:NSTimer射擊儘管失效並將其設置爲零
if(_pauseTimer) {
[_pauseTimer invalidate];
_pauseTimer=nil;
}
//Restart the pause timer.
_pauseTimer = [NSTimer scheduledTimerWithTimeInterval:_settings.pauseTime
target:self
selector:@selector(timerExpired:)
userInfo:_pauseTimer
repeats:NO];
然而,一旦予註釋掉_pauseTimer =零,它正確地表現;即,除非調用touchesMoved:withEvent:之間的時間爲_settings.pauseTime,否則它不會再次被觸發。爲什麼這個「老」_pauseTimer儘管失效並且設置爲零,
爲什麼你傳遞'_pauseTimer'作爲'userInfo'參數?這會導致計時器保留自己。您應該在那裏傳遞'nil'。 – jlehr
這不是一個答案,但你有沒有嘗試過這樣做呢..http://stackoverflow.com/questions/15383782/how-to-reset-nstimer-for-touch-touch-move-in-ios – Krishnan
Invalidate應該停止它...設置一個斷點 –