From b319db9a299b0136ed35c92c311775979894f5b0 Mon Sep 17 00:00:00 2001 From: brandon_withrow Date: Tue, 13 Jun 2017 14:25:21 -0700 Subject: [PATCH] Fixed bug with layer time being off by one frame --- .gitignore | 3 +++ .../xcschemes/xcschememanagement.plist | 27 ------------------- .../Classes/AnimatableLayers/LOTLayerView.m | 2 +- .../Extensions/CGGeometry+LOTAdditions.h | 1 - .../Extensions/CGGeometry+LOTAdditions.m | 1 - lottie-ios/Classes/Models/LOTComposition.m | 2 +- lottie-ios/Classes/Models/LOTLayer.m | 2 +- lottie-ios/Classes/Private/LOTAnimationView.m | 12 ++++----- 8 files changed, 12 insertions(+), 38 deletions(-) delete mode 100644 Example/lottie-ios.xcodeproj/xcuserdata/brandon_withrow.xcuserdatad/xcschemes/xcschememanagement.plist diff --git a/.gitignore b/.gitignore index b13780bf6c..5a8790d3f5 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ build/ Lottie-Screenshot/Lottie-Screenshot.xcworkspace/xcuserdata/ Lottie-Screenshot/Lottie-Screenshot.xcodeproj/xcuserdata/ Lottie-Screenshot/Pods/Pods.xcodeproj/xcuserdata/ +Example/.DS_Store +Example/lottie-ios.xcodeproj/xcuserdata +Example/lottie-ios.xcodeproj/xcuserdata \ No newline at end of file diff --git a/Example/lottie-ios.xcodeproj/xcuserdata/brandon_withrow.xcuserdatad/xcschemes/xcschememanagement.plist b/Example/lottie-ios.xcodeproj/xcuserdata/brandon_withrow.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index 46fd0c1067..0000000000 --- a/Example/lottie-ios.xcodeproj/xcuserdata/brandon_withrow.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,27 +0,0 @@ - - - - - SchemeUserState - - lottie-ios-Example.xcscheme_^#shared#^_ - - orderHint - 0 - - - SuppressBuildableAutocreation - - 6003F589195388D20070C39A - - primary - - - 6003F5AD195388D20070C39A - - primary - - - - - diff --git a/lottie-ios/Classes/AnimatableLayers/LOTLayerView.m b/lottie-ios/Classes/AnimatableLayers/LOTLayerView.m index 297b096c2a..b7770d477f 100644 --- a/lottie-ios/Classes/AnimatableLayers/LOTLayerView.m +++ b/lottie-ios/Classes/AnimatableLayers/LOTLayerView.m @@ -291,7 +291,7 @@ _inOutAnimation = inOutAnimation; _inOutAnimation.duration = self.layerDuration; [self addAnimation:_inOutAnimation forKey:@"inout"]; - self.duration = self.layerDuration + LOT_singleFrameTimeValue; + self.duration = self.layerDuration; } diff --git a/lottie-ios/Classes/Extensions/CGGeometry+LOTAdditions.h b/lottie-ios/Classes/Extensions/CGGeometry+LOTAdditions.h index 4397205eed..4b6fc82a91 100644 --- a/lottie-ios/Classes/Extensions/CGGeometry+LOTAdditions.h +++ b/lottie-ios/Classes/Extensions/CGGeometry+LOTAdditions.h @@ -8,7 +8,6 @@ // extern const CGSize CGSizeMax; -extern const NSTimeInterval LOT_singleFrameTimeValue; CGRect LOT_RectIntegral(CGRect rect); diff --git a/lottie-ios/Classes/Extensions/CGGeometry+LOTAdditions.m b/lottie-ios/Classes/Extensions/CGGeometry+LOTAdditions.m index fe570260f0..47c1e06283 100644 --- a/lottie-ios/Classes/Extensions/CGGeometry+LOTAdditions.m +++ b/lottie-ios/Classes/Extensions/CGGeometry+LOTAdditions.m @@ -2,7 +2,6 @@ #import "CGGeometry+LOTAdditions.h" const CGSize CGSizeMax = {CGFLOAT_MAX, CGFLOAT_MAX}; -const NSTimeInterval LOT_singleFrameTimeValue = 1.0 / 60.0; // // Core Graphics Geometry Additions // diff --git a/lottie-ios/Classes/Models/LOTComposition.m b/lottie-ios/Classes/Models/LOTComposition.m index 0511e24a26..2dd83f84e4 100644 --- a/lottie-ios/Classes/Models/LOTComposition.m +++ b/lottie-ios/Classes/Models/LOTComposition.m @@ -34,7 +34,7 @@ _framerate = [jsonDictionary[@"fr"] copy]; if (_startFrame && _endFrame && _framerate) { - NSInteger frameDuration = _endFrame.integerValue - _startFrame.integerValue; + NSInteger frameDuration = (_endFrame.integerValue - _startFrame.integerValue) - 1; NSTimeInterval timeDuration = frameDuration / _framerate.floatValue; _timeDuration = timeDuration; } diff --git a/lottie-ios/Classes/Models/LOTLayer.m b/lottie-ios/Classes/Models/LOTLayer.m index fbefd47d0c..b843f0001f 100644 --- a/lottie-ios/Classes/Models/LOTLayer.m +++ b/lottie-ios/Classes/Models/LOTLayer.m @@ -173,7 +173,7 @@ NSMutableArray *keys = [NSMutableArray array]; NSMutableArray *keyTimes = [NSMutableArray array]; - CGFloat layerLength = _outFrame.integerValue - 1; + CGFloat layerLength = _outFrame.integerValue; _layerDuration = (layerLength / _framerate.floatValue); if (_hasInAnimation) { diff --git a/lottie-ios/Classes/Private/LOTAnimationView.m b/lottie-ios/Classes/Private/LOTAnimationView.m index b9391891cf..46a27c8e5b 100644 --- a/lottie-ios/Classes/Private/LOTAnimationView.m +++ b/lottie-ios/Classes/Private/LOTAnimationView.m @@ -39,7 +39,7 @@ // Initial Setup of Layer _layer.fillMode = kCAFillModeBoth; - _layer.duration = _animationDuration; + _layer.duration = _animationDuration + (1.f / framerate.floatValue); _layer.speed = 0; _layer.timeOffset = 0; _layer.beginTime = CACurrentMediaTime(); @@ -131,7 +131,7 @@ _animationIsPlaying = NO; if (updateAnimation) { - CFTimeInterval offset = _animatedProgress == 1 ? _animationDuration - LOT_singleFrameTimeValue : _animatedProgress * _animationDuration; + CFTimeInterval offset = _animatedProgress == 1 ? _animationDuration : _animatedProgress * _animationDuration; __unused CFTimeInterval clock = CACurrentMediaTime(); [self updateAnimationLayerWithTimeOffset:offset]; } @@ -181,8 +181,8 @@ - (void)logStats:(NSString *)logName { CFTimeInterval localTime = [_layer convertTime:CACurrentMediaTime() fromLayer:nil]; - NSLog(@"LOTAnimationState %@ || Is Playing %@ || Duration %f || Speed %lf || Progress %lf || Local Time %lf || Frame %i ", - logName, (_animationIsPlaying ? @"YES" : @"NO"), self.animationDuration, _layer.speed, self.animatedProgress, localTime, (int)(localTime * _framerate.integerValue)); + NSLog(@"LOTAnimationState %@ || Is Playing %@ || Duration %f || Speed %lf || Progress %lf || Local Time %lf || Frame %lf ", + logName, (_animationIsPlaying ? @"YES" : @"NO"), self.animationDuration, _layer.speed, self.animatedProgress, localTime, floorf(localTime * _framerate.floatValue)); } @end @@ -270,7 +270,7 @@ [self _initializeAnimationContainer]; [self _setupWithSceneModel:laScene restoreAnimationState:NO]; } else { - _animationState = [[LOTAnimationState alloc] initWithDuration:LOT_singleFrameTimeValue layer:nil frameRate:@1]; + _animationState = [[LOTAnimationState alloc] initWithDuration:1.f/60.f layer:nil frameRate:@1]; dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){ NSData *animationData = [NSData dataWithContentsOfURL:url]; if (!animationData) { @@ -329,7 +329,7 @@ _sceneModel = model; [self _buildSubviewsFromModel]; LOTAnimationState *oldState = _animationState; - _animationState = [[LOTAnimationState alloc] initWithDuration:_sceneModel.timeDuration + LOT_singleFrameTimeValue layer:_timingLayer frameRate:_sceneModel.framerate]; + _animationState = [[LOTAnimationState alloc] initWithDuration:_sceneModel.timeDuration layer:_timingLayer frameRate:_sceneModel.framerate]; if (restoreAnimation && oldState) { [self setLoopAnimation:oldState.loopAnimation];