Skip to content

Instantly share code, notes, and snippets.

@mallorypaine
Created December 20, 2013 01:38
Show Gist options
  • Save mallorypaine/8049184 to your computer and use it in GitHub Desktop.
Save mallorypaine/8049184 to your computer and use it in GitHub Desktop.
IFTTAnimation accumulates errors in a subtle way. Every time you add an animation, the timeline gets one extra entry. Here's my fix. Note that the inner for-loop used to break when j <= nextKeyFrameTime. Suppose you have keyFrames at times 100, 200, and 300. With <= nextKeyFrameTime, you'll get two entries for time 100, 200, and 300, and you'll …
self.timeline = [NSMutableArray new];
for (NSUInteger i = 0; i < self.keyFrames.count - 1; i++) {
IFTTTAnimationKeyFrame *keyFrame = [self.keyFrames objectAtIndex:i];
IFTTTAnimationKeyFrame *nextKeyFrame = [self.keyFrames objectAtIndex:i+1];
NSInteger j;
for (j = keyFrame.time; j < nextKeyFrame.time; j++) {
[self.timeline addObject:[self frameForTime:j startKeyFrame:keyFrame endKeyFrame:nextKeyFrame]];
}
if (i + 1 == self.keyFrames.count - 1) {
[self.timeline addObject:[self frameForTime:j startKeyFrame:keyFrame endKeyFrame:nextKeyFrame]];
}
}
self.startTime = ((IFTTTAnimationKeyFrame *)[self.keyFrames objectAtIndex:0]).time;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment