0
我正在使用自定義的矩形定時器作爲我的iWatch中的WKInterfaceImage。我們的想法是將持續時間設置爲定時器的長度,然後將定時器縮短爲長度= 0。只要它允許運行整個動畫,它就可以正常工作。但是,如果我嘗試更改動畫運行時的計時器長度,則會將新長度添加到當前長度。如何更新正在運行的WKInterfaceImage動畫?
所以基本上問題是,當我嘗試添加一個新的長度時,它將舊的和新的長度結合到了定時器中,這使得它變得很長。
真的很感謝一些幫助。
Here's代碼:
-(void)setAnimatedTimer {
NSLog(@"timer called");
NSUserDefaults* defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.daypal"];
NSDate *NextActivityStartTime = [defaults objectForKey:@"watchStartDate"];
NSDate *NextActivityEndTime = [defaults objectForKey:@"watchStopDate"];
NSTimeInterval fromStartTimeToNow = [NextActivityStartTime timeIntervalSinceNow];
NSTimeInterval fromEndTimeToNow = [NextActivityEndTime timeIntervalSinceNow];
NSTimeInterval watchDuration = fromEndTimeToNow - fromStartTimeToNow;
if (fromStartTimeToNow > 0 && fromEndTimeToNow > 0) {
_watchActivityTimer.hidden = YES;
int watbchdurationlenght = watchDuration/100;
[self.watchActivityTimer setRelativeWidth:watchDurationLenght withAdjustment:0.0];
[self animateWithDuration:watchDuration animations:^{
// [self.watchActivityTimer setHorizontalAlignment:WKInterfaceObjectHorizontalAlignmentRight];
[self.watchActivityTimer setWidth:0];
}];
}