diff --git a/LotteAnimator.xcodeproj/project.pbxproj b/LotteAnimator.xcodeproj/project.pbxproj index 226c611970..8d38e15d72 100644 --- a/LotteAnimator.xcodeproj/project.pbxproj +++ b/LotteAnimator.xcodeproj/project.pbxproj @@ -85,6 +85,7 @@ 62FE40EC1D402C0200CA389D /* parentTest.json in Resources */ = {isa = PBXBuildFile; fileRef = 62FE40EB1D402C0200CA389D /* parentTest.json */; }; 62FE41161D41526D00CA389D /* InOutAnimation.json in Resources */ = {isa = PBXBuildFile; fileRef = 62FE41151D41526D00CA389D /* InOutAnimation.json */; }; 62FE41431D41862200CA389D /* LAAnimatableLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 62FE41421D41862200CA389D /* LAAnimatableLayer.m */; }; + 62FE41BC1D42DD8500CA389D /* LAMaskLayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 62FE41BB1D42DD8500CA389D /* LAMaskLayer.m */; }; F5B4E946F7B28B4594824641 /* libPods-LotteAnimator.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BC68632413866F85CEACB7EA /* libPods-LotteAnimator.a */; }; /* End PBXBuildFile section */ @@ -203,6 +204,8 @@ 62FE41151D41526D00CA389D /* InOutAnimation.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = InOutAnimation.json; sourceTree = ""; }; 62FE41411D41862200CA389D /* LAAnimatableLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LAAnimatableLayer.h; sourceTree = ""; }; 62FE41421D41862200CA389D /* LAAnimatableLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LAAnimatableLayer.m; sourceTree = ""; }; + 62FE41BA1D42DD8500CA389D /* LAMaskLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LAMaskLayer.h; sourceTree = ""; }; + 62FE41BB1D42DD8500CA389D /* LAMaskLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LAMaskLayer.m; sourceTree = ""; }; AEE1A33E4CE2F6024DE7793E /* Pods-LotteAnimator.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LotteAnimator.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LotteAnimator/Pods-LotteAnimator.debug.xcconfig"; sourceTree = ""; }; BC68632413866F85CEACB7EA /* libPods-LotteAnimator.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LotteAnimator.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -258,6 +261,8 @@ 62FE41421D41862200CA389D /* LAAnimatableLayer.m */, 4804B32A1C1F835F00DA8AF7 /* LALayerView.h */, 4804B32B1C1F835F00DA8AF7 /* LALayerView.m */, + 62FE41BA1D42DD8500CA389D /* LAMaskLayer.h */, + 62FE41BB1D42DD8500CA389D /* LAMaskLayer.m */, 620CD7E31D38180800055AD1 /* LAGroupLayerView.h */, 620CD7E41D38180800055AD1 /* LAGroupLayerView.m */, 486BE04C1D36F1BE00CD14A0 /* LAShapeLayerView.h */, @@ -608,6 +613,7 @@ 620CD7CD1D3415F000055AD1 /* LAAnimatableRectValue.m in Sources */, 620A565C1D1C81610030EBFB /* LAAnimatableColorValue.m in Sources */, 48372A5E1C209A8900AD0293 /* LAShapeTransform.m in Sources */, + 62FE41BC1D42DD8500CA389D /* LAMaskLayer.m in Sources */, 620CD7D01D343A2500055AD1 /* LAAnimatableScaleValue.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/LotteAnimator.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/UserInterfaceState.xcuserstate b/LotteAnimator.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/UserInterfaceState.xcuserstate index 98132bb68d..a5086395d7 100644 Binary files a/LotteAnimator.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/UserInterfaceState.xcuserstate and b/LotteAnimator.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/LotteAnimator.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/LotteAnimator.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 095166b5a1..453d7341b4 100644 --- a/LotteAnimator.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/LotteAnimator.xcworkspace/xcuserdata/brandon_withrow.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -45,22 +45,6 @@ landmarkType = "5"> - - - - - - - - @@ -147,13 +115,45 @@ shouldBeEnabled = "Yes" ignoreCount = "0" continueAfterRunningActions = "No" - filePath = "LotteAnimator/LAAnimatableLayer.m" - timestampString = "490837507.04002" + filePath = "LotteAnimator/LALayerView.m" + timestampString = "490921111.145475" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "48" - endingLineNumber = "48" - landmarkName = "-setAnimationProgress:" + startingLineNumber = "128" + endingLineNumber = "128" + landmarkName = "-_setupViewFromModel" + landmarkType = "5"> + + + + + + + + diff --git a/LotteAnimator/CAAnimationGroup+LAAnimatableGroup.m b/LotteAnimator/CAAnimationGroup+LAAnimatableGroup.m index 52277afd2c..62f4a1f17e 100644 --- a/LotteAnimator/CAAnimationGroup+LAAnimatableGroup.m +++ b/LotteAnimator/CAAnimationGroup+LAAnimatableGroup.m @@ -10,17 +10,17 @@ @implementation CAAnimationGroup (LAAnimatableGroup) -+ (nullable CAAnimationGroup *)animationGroupForAnimatablePropertiesWithKeyPaths:(nonnull NSDictionary> *)properties; { ++ (nullable CAAnimationGroup *)animationGroupForAnimatablePropertiesWithKeyPaths:(nonnull NSDictionary> *)properties { NSMutableArray *animations = [NSMutableArray array]; - NSTimeInterval duration = 0; + NSTimeInterval animduration = 0; for (NSString *keyPath in properties.allKeys) { id property = properties[keyPath]; if ([property hasAnimation]) { CAKeyframeAnimation *animation = [property animationForKeyPath:keyPath]; [animations addObject:animation]; - if (animation.duration + animation.beginTime > duration) { - duration = animation.duration + animation.beginTime; + if (animation.duration + animation.beginTime > animduration) { + animduration = animation.duration + animation.beginTime; } } } @@ -28,7 +28,7 @@ if (animations.count) { CAAnimationGroup *animation = [CAAnimationGroup new]; animation.animations = animations; - animation.duration = duration; + animation.duration = animduration; animation.fillMode = kCAFillModeForwards; animation.removedOnCompletion = NO; return animation; diff --git a/LotteAnimator/LAAnimatableLayer.h b/LotteAnimator/LAAnimatableLayer.h index 0a9db53ed1..437d5f29a2 100644 --- a/LotteAnimator/LAAnimatableLayer.h +++ b/LotteAnimator/LAAnimatableLayer.h @@ -10,8 +10,11 @@ @interface LAAnimatableLayer : CALayer +- (instancetype)initWithDuration:(NSTimeInterval)duration NS_DESIGNATED_INITIALIZER; + @property (nonatomic, strong) NSArray *animationSublayers; @property (nonatomic, strong) NSArray *childLayers; +@property (nonatomic, readonly) NSTimeInterval laAnimationDuration; @property (nonatomic, assign) BOOL loopAnimation; @property (nonatomic, assign) BOOL autoReverseAnimation; diff --git a/LotteAnimator/LAAnimatableLayer.m b/LotteAnimator/LAAnimatableLayer.m index 1f5cc86e41..08c12c777f 100644 --- a/LotteAnimator/LAAnimatableLayer.m +++ b/LotteAnimator/LAAnimatableLayer.m @@ -10,6 +10,14 @@ @implementation LAAnimatableLayer +- (instancetype)initWithDuration:(NSTimeInterval)duration { + self = [super init]; + if (self) { + _laAnimationDuration = duration; + } + return self; +} + - (void)play { [self _resumeLayer:self]; for (CALayer *layer in self.animationSublayers) { @@ -44,18 +52,18 @@ } - (void)setAnimationProgress:(CGFloat)animationProgress { - self.speed = 0.0; + self.speed = 0; self.timeOffset = 0.0; self.beginTime = 0.0; self.beginTime = [self convertTime:CACurrentMediaTime() fromLayer:nil]; - self.timeOffset = [self convertTime:CACurrentMediaTime() fromLayer:nil] + animationProgress; + self.timeOffset = animationProgress * self.laAnimationDuration; for (CALayer *layer in self.animationSublayers) { - layer.speed = 0.0; + layer.speed = 0; layer.timeOffset = 0.0; layer.beginTime = 0.0; layer.beginTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; - layer.timeOffset = [layer convertTime:CACurrentMediaTime() fromLayer:nil] + animationProgress; + layer.timeOffset = animationProgress * self.laAnimationDuration; } for (LAAnimatableLayer *layer in self.childLayers) { @@ -76,18 +84,13 @@ } -(void)_pauseLayer:(CALayer*)layer { - CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; layer.speed = 0.0; - layer.timeOffset = pausedTime; } -(void)_resumeLayer:(CALayer*)layer { - CFTimeInterval pausedTime = [layer timeOffset]; layer.speed = 1.0; layer.timeOffset = 0.0; - layer.beginTime = 0.0; - CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime; - layer.beginTime = timeSincePause; + layer.beginTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; } diff --git a/LotteAnimator/LACompView.m b/LotteAnimator/LACompView.m index 08f7e2e978..451393b53d 100644 --- a/LotteAnimator/LACompView.m +++ b/LotteAnimator/LACompView.m @@ -43,12 +43,6 @@ - (void)setDebugModeOn:(BOOL)debugModeOn { _debugModeOn = debugModeOn; - for (LALayerView *child in _layerMap.allValues) { - if ([child isKindOfClass:[LALayerView class]]) { - [child setDebugModeOn:debugModeOn]; - child.opacity = debugModeOn ? 0.5 : 1; - } - } } - (void)play { @@ -66,10 +60,24 @@ } - (void)setAnimationProgress:(CGFloat)animationProgress { + _animationProgress = animationProgress; for (LALayerView *layerView in _layerMap.allValues) { [layerView setAnimationProgress:animationProgress]; } } +- (void)setLoopAnimation:(BOOL)loopAnimation { + _loopAnimation = loopAnimation; + for (LALayerView *layerView in _layerMap.allValues) { + [layerView setLoopAnimation:loopAnimation]; + } +} + +- (void)setAutoReverseAnimation:(BOOL)autoReverseAnimation { + _autoReverseAnimation = autoReverseAnimation; + for (LALayerView *layerView in _layerMap.allValues) { + [layerView setAutoReverseAnimation:autoReverseAnimation]; + } +} @end diff --git a/LotteAnimator/LAGroupLayerView.h b/LotteAnimator/LAGroupLayerView.h index bbb5398d38..a47d95cd79 100644 --- a/LotteAnimator/LAGroupLayerView.h +++ b/LotteAnimator/LAGroupLayerView.h @@ -15,12 +15,11 @@ @interface LAGroupLayerView : LAAnimatableLayer - (instancetype)initWithShapeGroup:(LAShapeGroup *)shapeGroup - transform:(LAShapeTransform *)transform; + transform:(LAShapeTransform *)transform + withDuration:(NSTimeInterval)duration; @property (nonatomic, readonly) LAShapeGroup *shapeGroup; @property (nonatomic, readonly) LAShapeTransform *shapeTransform; @property (nonatomic, assign) BOOL debugModeOn; -- (void)startAnimation; - @end diff --git a/LotteAnimator/LAGroupLayerView.m b/LotteAnimator/LAGroupLayerView.m index 7a5c7d36aa..5485d45f19 100644 --- a/LotteAnimator/LAGroupLayerView.m +++ b/LotteAnimator/LAGroupLayerView.m @@ -18,8 +18,9 @@ } - (instancetype)initWithShapeGroup:(LAShapeGroup *)shapeGroup - transform:(LAShapeTransform *)transform { - self = [super init]; + transform:(LAShapeTransform *)transform + withDuration:(NSTimeInterval)duration { + self = [super initWithDuration:duration]; if (self) { _shapeGroup = shapeGroup; _shapeTransform = transform; @@ -60,7 +61,8 @@ LAShapeLayerView *shapeLayer = [[LAShapeLayerView alloc] initWithShape:shapePath fill:currentFill stroke:currentStroke - transform:currentTransform]; + transform:currentTransform + withDuration:self.laAnimationDuration]; [shapeLayers addObject:shapeLayer]; [self addSublayer:shapeLayer]; } else if ([item isKindOfClass:[LAShapeRectangle class]]) { @@ -68,13 +70,15 @@ LARectShapeLayer *shapeLayer = [[LARectShapeLayer alloc] initWithRectShape:shapeRect fill:currentFill stroke:currentStroke - transform:currentTransform]; + transform:currentTransform + withDuration:self.laAnimationDuration]; [shapeLayers addObject:shapeLayer]; [self addSublayer:shapeLayer]; } else if ([item isKindOfClass:[LAShapeGroup class]]) { LAShapeGroup *shapeGroup = (LAShapeGroup *)item; LAGroupLayerView *groupLayer = [[LAGroupLayerView alloc] initWithShapeGroup:shapeGroup - transform:currentTransform]; + transform:currentTransform + withDuration:self.laAnimationDuration]; [groupLayers addObject:groupLayer]; [self addSublayer:groupLayer]; } diff --git a/LotteAnimator/LALayer.h b/LotteAnimator/LALayer.h index b77efd9112..ce5e1cfebe 100644 --- a/LotteAnimator/LALayer.h +++ b/LotteAnimator/LALayer.h @@ -52,6 +52,8 @@ typedef enum : NSInteger { @property (nonatomic, readonly) LAAnimatablePointValue *anchor; @property (nonatomic, readonly) LAAnimatableScaleValue *scale; +@property (nonatomic, readonly) BOOL hasOutAnimation; +@property (nonatomic, readonly) BOOL hasInAnimation; @property (nonatomic, readonly) BOOL hasInOutAnimation; @property (nonatomic, readonly) NSArray *inOutKeyframes; @property (nonatomic, readonly) NSArray *inOutKeyTimes; diff --git a/LotteAnimator/LALayer.m b/LotteAnimator/LALayer.m index 078e534bc6..3ec1c1d0fe 100644 --- a/LotteAnimator/LALayer.m +++ b/LotteAnimator/LALayer.m @@ -92,15 +92,15 @@ } _shapes = shapes; - BOOL hasInAnmation = (_inFrame.integerValue > composition.startFrame.integerValue); - BOOL hasOutAnimation = (_outFrame.integerValue < composition.endFrame.integerValue); - _hasInOutAnimation = hasInAnmation || hasOutAnimation; + _hasInAnimation = (_inFrame.integerValue > composition.startFrame.integerValue); + _hasOutAnimation = (_outFrame.integerValue < composition.endFrame.integerValue); + _hasInOutAnimation = _hasInAnimation || _hasOutAnimation; if (_hasInOutAnimation) { NSMutableArray *keys = [NSMutableArray array]; NSMutableArray *keyTimes = [NSMutableArray array]; CGFloat compLength = composition.endFrame.floatValue - composition.startFrame.floatValue; - if (hasInAnmation) { + if (_hasInAnimation) { [keys addObject:@1]; [keyTimes addObject:@0]; [keys addObject:@0]; @@ -111,7 +111,7 @@ [keyTimes addObject:@0]; } - if (hasOutAnimation) { + if (_hasOutAnimation) { [keys addObject:@1]; CGFloat outTime = _outFrame.floatValue / compLength; [keyTimes addObject:@(outTime)]; diff --git a/LotteAnimator/LALayerView.m b/LotteAnimator/LALayerView.m index 810fa3996d..48401872b4 100644 --- a/LotteAnimator/LALayerView.m +++ b/LotteAnimator/LALayerView.m @@ -13,8 +13,7 @@ @interface LAParentLayer : LAAnimatableLayer -- (instancetype)initWithParentModel:(LALayer *)parent compBounds:(CGRect)bounds; -- (void)startAnimation; +- (instancetype)initWithParentModel:(LALayer *)parent inComposition:(LAComposition *)comp; @end @@ -23,10 +22,10 @@ CAAnimationGroup *_animation; } -- (instancetype)initWithParentModel:(LALayer *)parent compBounds:(CGRect)bounds { - self = [super init]; +- (instancetype)initWithParentModel:(LALayer *)parent inComposition:(LAComposition *)comp { + self = [super initWithDuration:comp.timeDuration]; if (self) { - self.bounds = bounds; + self.bounds = comp.compBounds; _parentModel = parent; [self _setupLayerFromModel]; } @@ -59,19 +58,22 @@ CAAnimationGroup *_animation; CAKeyframeAnimation *_inOutAnimation; NSArray *_parentLayers; + LAComposition *_composition; + } - (instancetype)initWithModel:(LALayer *)model inComposition:(LAComposition *)comp { - self = [super init]; + self = [super initWithDuration:comp.timeDuration]; if (self) { _layerModel = model; - [self _setupViewFromModelInComposition:comp]; + _composition = comp; + [self _setupViewFromModel]; } return self; } -- (void)_setupViewFromModelInComposition:(LAComposition *)comp { - self.bounds = comp.compBounds; +- (void)_setupViewFromModel { + self.bounds = _composition.compBounds; self.anchorPoint = CGPointZero; _childContainerLayer = [CALayer new]; self.animationSublayers = @[_childContainerLayer]; @@ -81,8 +83,8 @@ NSMutableArray *parentLayers = [NSMutableArray array]; if (parentID) { while (parentID != nil) { - LALayer *parentModel = [comp layerModelForID:parentID]; - LAParentLayer *parentLayer = [[LAParentLayer alloc] initWithParentModel:parentModel compBounds:comp.compBounds]; + LALayer *parentModel = [_composition layerModelForID:parentID]; + LAParentLayer *parentLayer = [[LAParentLayer alloc] initWithParentModel:parentModel inComposition:_composition]; [parentLayer addSublayer:currentChild]; [parentLayers addObject:parentLayer]; currentChild = parentLayer; @@ -99,7 +101,7 @@ _childContainerLayer.anchorPoint = _layerModel.anchor.initialPoint; _childContainerLayer.transform = _layerModel.scale.initialScale; _childContainerLayer.sublayerTransform = CATransform3DMakeRotation(_layerModel.rotation.initialValue.floatValue, 0, 0, 1); - self.hidden = _layerModel.inFrame.integerValue > comp.startFrame.integerValue; + self.hidden = _layerModel.hasInAnimation; NSArray *groupItems = _layerModel.shapes; NSArray *reversedItems = [[groupItems reverseObjectEnumerator] allObjects]; @@ -109,7 +111,7 @@ for (id item in reversedItems) { if ([item isKindOfClass:[LAShapeGroup class]]) { - LAGroupLayerView *groupLayer = [[LAGroupLayerView alloc] initWithShapeGroup:(LAShapeGroup *)item transform:currentTransform]; + LAGroupLayerView *groupLayer = [[LAGroupLayerView alloc] initWithShapeGroup:(LAShapeGroup *)item transform:currentTransform withDuration:self.laAnimationDuration]; [_childContainerLayer addSublayer:groupLayer]; [shapeLayers addObject:groupLayer]; } else if ([item isKindOfClass:[LAShapeTransform class]]) { @@ -135,7 +137,6 @@ @"transform" : _layerModel.scale, @"sublayerTransform.rotation" : _layerModel.rotation}]; - if (_animation) { [_childContainerLayer addAnimation:_animation forKey:@"lotteAnimation"]; } @@ -150,14 +151,11 @@ inOutAnimation.removedOnCompletion = NO; _inOutAnimation = inOutAnimation; + _inOutAnimation.duration = self.laAnimationDuration; [self addAnimation:_inOutAnimation forKey:@""]; } } -- (void)_viewtapped { - NSLog(@"%@", self.layerModel); -} - - (void)setDebugModeOn:(BOOL)debugModeOn { _debugModeOn = debugModeOn; self.borderColor = debugModeOn ? [UIColor redColor].CGColor : nil; diff --git a/LotteAnimator/LAMaskLayer.h b/LotteAnimator/LAMaskLayer.h new file mode 100644 index 0000000000..31a8574499 --- /dev/null +++ b/LotteAnimator/LAMaskLayer.h @@ -0,0 +1,18 @@ +// +// LAMaskLayer.h +// LotteAnimator +// +// Created by brandon_withrow on 7/22/16. +// Copyright © 2016 Brandon Withrow. All rights reserved. +// + +#import "LAAnimatableLayer.h" + +@interface LAMaskLayer : LAAnimatableLayer + +- (instancetype)initWithMasks:(NSArray *)masks inComposition:(LAComposition *)comp; + +@property (nonatomic, readonly) NSArray *masks; + + +@end diff --git a/LotteAnimator/LAMaskLayer.m b/LotteAnimator/LAMaskLayer.m new file mode 100644 index 0000000000..7597656564 --- /dev/null +++ b/LotteAnimator/LAMaskLayer.m @@ -0,0 +1,29 @@ +// +// LAMaskLayer.m +// LotteAnimator +// +// Created by brandon_withrow on 7/22/16. +// Copyright © 2016 Brandon Withrow. All rights reserved. +// + +#import "LAMaskLayer.h" + +@implementation LAMaskLayer { + LAComposition *_composition; +} + +- (instancetype)initWithMasks:(NSArray *)masks inComposition:(LAComposition *)comp { + self = [super initWithDuration:comp.timeDuration]; + if (self) { + _masks = masks; + _composition = comp; + [self _setupViewFromModel]; + } + return self; +} + +- (void)_setupViewFromModel { + +} + +@end diff --git a/LotteAnimator/LARectShapeLayer.h b/LotteAnimator/LARectShapeLayer.h index a88c95524b..7dd331635e 100644 --- a/LotteAnimator/LARectShapeLayer.h +++ b/LotteAnimator/LARectShapeLayer.h @@ -14,9 +14,7 @@ - (instancetype)initWithRectShape:(LAShapeRectangle *)rectShape fill:(LAShapeFill *)fill stroke:(LAShapeStroke *)stroke - transform:(LAShapeTransform *)transform; - -- (void)startAnimation; - + transform:(LAShapeTransform *)transform + withDuration:(NSTimeInterval)duration; @end diff --git a/LotteAnimator/LARectShapeLayer.m b/LotteAnimator/LARectShapeLayer.m index 6015f21af7..c1a7a5c7d2 100644 --- a/LotteAnimator/LARectShapeLayer.m +++ b/LotteAnimator/LARectShapeLayer.m @@ -7,6 +7,7 @@ // #import "LARectShapeLayer.h" +#import "CAAnimationGroup+LAAnimatableGroup.h" @implementation LARectShapeLayer { LAShapeTransform *_transform; @@ -25,14 +26,16 @@ - (instancetype)initWithRectShape:(LAShapeRectangle *)rectShape fill:(LAShapeFill *)fill stroke:(LAShapeStroke *)stroke - transform:(LAShapeTransform *)transform { - self = [super init]; + transform:(LAShapeTransform *)transform + withDuration:(NSTimeInterval)duration { + self = [super initWithDuration:duration]; if (self) { _rectangle = rectShape; _stroke = stroke; _fill = fill; _transform = transform; + self.allowsEdgeAntialiasing = YES; self.frame = _transform.compBounds; self.anchorPoint = _transform.anchor.initialPoint; self.opacity = _transform.opacity.initialValue.floatValue; @@ -67,11 +70,34 @@ } - (void)_buildAnimation { + if (_transform) { + _animation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"opacity" : _transform.opacity, + @"position" : _transform.position, + @"anchorPoint" : _transform.anchor, + @"transform" : _transform.scale, + @"sublayerTransform.rotation" : _transform.rotation}]; + [self addAnimation:_animation forKey:@"LotteAnimation"]; + } -} + if (_stroke) { + _strokeAnimation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"strokeColor" : _stroke.color, + @"opacity" : _stroke.opacity, + @"lineWidth" : _stroke.width, + @"bounds" : _rectangle.bounds, + @"position" : _rectangle.position, + @"cornerRadius" : _rectangle.cornerRadius}]; + [_strokeLayer addAnimation:_strokeAnimation forKey:@""]; -- (void)startAnimation { + } + if (_fill) { + _fillAnimation = [CAAnimationGroup animationGroupForAnimatablePropertiesWithKeyPaths:@{@"backgroundColor" : _fill.color, + @"opacity" : _fill.opacity, + @"bounds" : _rectangle.bounds, + @"position" : _rectangle.position, + @"cornerRadius" : _rectangle.cornerRadius}]; + [_fillLayer addAnimation:_fillAnimation forKey:@""]; + } } @end diff --git a/LotteAnimator/LAShapeLayerView.h b/LotteAnimator/LAShapeLayerView.h index b15eb26e81..0cb38abe38 100644 --- a/LotteAnimator/LAShapeLayerView.h +++ b/LotteAnimator/LAShapeLayerView.h @@ -14,7 +14,8 @@ - (instancetype)initWithShape:(LAShapePath *)shape fill:(LAShapeFill *)fill stroke:(LAShapeStroke *)stroke - transform:(LAShapeTransform *)transform; + transform:(LAShapeTransform *)transform + withDuration:(NSTimeInterval)duration; - (void)startAnimation; diff --git a/LotteAnimator/LAShapeLayerView.m b/LotteAnimator/LAShapeLayerView.m index 48fe753583..2d7ec48720 100644 --- a/LotteAnimator/LAShapeLayerView.m +++ b/LotteAnimator/LAShapeLayerView.m @@ -26,8 +26,9 @@ - (instancetype)initWithShape:(LAShapePath *)shape fill:(LAShapeFill *)fill stroke:(LAShapeStroke *)stroke - transform:(LAShapeTransform *)transform { - self = [super init]; + transform:(LAShapeTransform *)transform + withDuration:(NSTimeInterval)duration { + self = [super initWithDuration:duration]; if (self) { _path = shape; _stroke = stroke; diff --git a/LotteAnimator/ViewController.m b/LotteAnimator/ViewController.m index 56c8c7b74e..0d4d51c065 100644 --- a/LotteAnimator/ViewController.m +++ b/LotteAnimator/ViewController.m @@ -293,7 +293,7 @@ self.currentScene = laScene; self.currentSceneView = compView; [self.view sendSubviewToBack:self.currentSceneView]; - [compView performSelector:@selector(play) withObject:nil afterDelay:1]; - [compView performSelector:@selector(pause) withObject:nil afterDelay:2]; + compView.loopAnimation = YES; + [compView play]; } @end