我有一個秒錶類,它在其tick
方法中定期更新視圖。該方法通過觸發在Apple Watch上不可靠的performSelectorAfterDelay
[self performSelector:@selector(tick) withObject:self afterDelay:0.1f];
這工作正常的iPhone視圖獲取更新大約。每十分之一秒。
現在我想在Apple Watch上使用相同的類來實現此目的。當我啓動秒錶時,視圖會得到更新。但是,2秒後,幀率下降,秒錶變得無法使用。
這裏是整個tick
方法:
- (void)tick {
if (!self.running) return;
NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];
NSTimeInterval elapsed = currentTime - startTime;
if (countdown) {
curTime = originalTime - (elapsed * 1000);
}else {
curTime = originalTime + (elapsed * 1000);
curTime -= offset;
}
[self.delegate stopwatch:self tick:curTime];
long thisThousand = curTime/1000;
if (curTime > 0 || !countdown) {
if (thisThousand != lastThousand) {
long seconds = curTime/1000;
if (countdown) seconds++;
[self.delegate stopwatch:self fullSecond:seconds];
}
lastThousand = curTime/1000;
[self performSelector:@selector(tick) withObject:self afterDelay:0.1f];
} else {
curTime = 0;
[self.delegate stopwatch:self fullSecond:0];
[self.delegate stopwatchStoped:self];
[self stopTimer];
}
}
如何得到那個工作任何想法。還是另一種解決方案?
非常感謝!
編輯: 用戶界面只是一個簡單的標籤,而不是一個奇特的動畫。標籤應該設置爲0:00:00.1至0:00:00.2等等。
值得指出的是Core Animation目前在WatchKit中不可用。 – bgilham
啊。這很煩人。希望它會很快,然後你都可以upvote這個優秀的答案。 –