From ab75236c5f0dcbedfaa6af51b182a75c0413a93f Mon Sep 17 00:00:00 2001 From: Michael Welsh Date: Thu, 17 Aug 2017 17:05:20 -0400 Subject: [PATCH] Revert some of the animationProgress changes to revert to reflect absolutes - Update header documentation to make it clear how animatinoSpeed and animationProgress interact - Leave fixes in there that stop reversed animations "snapping" back --- lottie-ios/Classes/Private/LOTAnimationView.m | 26 +++---------------- .../Classes/PublicHeaders/LOTAnimationView.h | 5 +++- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/lottie-ios/Classes/Private/LOTAnimationView.m b/lottie-ios/Classes/Private/LOTAnimationView.m index 0fe50627cc..ea1375b3fa 100644 --- a/lottie-ios/Classes/Private/LOTAnimationView.m +++ b/lottie-ios/Classes/Private/LOTAnimationView.m @@ -210,27 +210,14 @@ static NSString * const kCompContainerAnimationKey = @"play"; if (!_sceneModel) { return 0; } - CGFloat absoluteProgress = ((frame.floatValue - _sceneModel.startFrame.floatValue) / (_sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue)); - if ([self _isPlayingForwards]) { - return absoluteProgress; - } else { - // If the animation is playing backwards, the progress is inverted. - return 1 - absoluteProgress; - } + return ((frame.floatValue - _sceneModel.startFrame.floatValue) / (_sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue)); } - (NSNumber *)_frameForProgress:(CGFloat)progress { if (!_sceneModel) { return @0; } - CGFloat absoluteProgress = ((_sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue) * progress); - if ([self _isPlayingForwards]) { - // If we're moving forward, then add the absolute progress to the start. - return @(absoluteProgress + _sceneModel.startFrame.floatValue); - } else { - // It the animation is playing backwards, subtract the progress from the end. - return @(_sceneModel.endFrame.floatValue - absoluteProgress); - } + return @(((_sceneModel.endFrame.floatValue - _sceneModel.startFrame.floatValue) * progress) + _sceneModel.startFrame.floatValue); } - (BOOL)_isPlayingForwards { @@ -397,18 +384,11 @@ static NSString * const kCompContainerAnimationKey = @"play"; } -(void)setAnimationSpeed:(CGFloat)animationSpeed { - BOOL directionChange = NO; - if ((animationSpeed >= 0 && _animationSpeed < 0) || (animationSpeed < 0 && _animationSpeed >= 0)) { - directionChange = YES; - } _animationSpeed = animationSpeed; - NSNumber *frame = [_compContainer.presentationLayer.currentFrame copy]; if (_isAnimationPlaying && _sceneModel) { + NSNumber *frame = [_compContainer.presentationLayer.currentFrame copy]; [self setProgressWithFrame:frame callCompletionIfNecessary:NO]; [self playFromFrame:_playRangeStartFrame toFrame:_playRangeEndFrame withCompletion:self.completionBlock]; - } else if (directionChange) { - // The progress needs to be re-calculated if the speed direction changes if the animation is not playing. - _animationProgress = [self _progressForFrame:frame]; } } diff --git a/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h b/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h index 0ae5534e86..5bfb9f3c3f 100644 --- a/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h +++ b/lottie-ios/Classes/PublicHeaders/LOTAnimationView.h @@ -46,9 +46,12 @@ typedef void (^LOTAnimationCompletionBlock)(BOOL animationFinished); // TODO /// Sets a progress from 0 - 1 of the animation. If the animation is playing it will stop and the compeltion block will be called. +/// The animation progress is in terms of absolute progress of the defined animation and does not +/// take into account negative speeds. @property (nonatomic, assign) CGFloat animationProgress; -/// Sets the speed of the animation. Accepts a negative value for reversing animation +/// Sets the speed of the animation. Accepts a negative value for reversing animation. +/// Negative speeds do not affect animationProgress @property (nonatomic, assign) CGFloat animationSpeed; /// Read only of the duration in seconds of the animation at speed of 1