2017-06-17 60 views
0

我有一個子畫面的時間「拍攝」更精靈使用計時器秒每x量:獲取殘留在定時器的時間間隔在夫特

:那麼所述時間間隔由下式定義

self.shootingEngine = Timer.scheduledTimer(timeInterval: (Double(60)/Double(self.ratePerMinute)), target: self, selector: #selector(ShootingEnemy.shoot), userInfo: nil, repeats: true) 

(Double(60)/Double(self.ratePerMinute)) // Let's say it is 2 seconds. 

時間間隔,在本例中爲2秒。它每2秒觸發一次shoot()方法。現在,我想知道如何獲得剩餘時間,直到Timer再次運行shoot()方法。舉例來說,我想知道有剩餘,直到下一次拍攝()

我想用這個0.74秒:

NSDate().timeIntervalSince1970 * 1000 

,節省了時間到一個變量,然後就尋找具有差異當前時間。但是,我首先想要檢查是否有一種更簡單的方法來避免存儲另一個實例變量。

+0

只需使用日期 –

回答

0

let timeRemaining = shootingEngine.fireDate.timeIntervalSince(Date()) 

讓我知道,如果您有任何其他問題。祝你好運!