Skip to content

Commit

Permalink
Added time progress, started building masks
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Withrow committed Jul 22, 2016
1 parent af697b6 commit aa17a9d
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 101 deletions.
6 changes: 6 additions & 0 deletions LotteAnimator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -203,6 +204,8 @@
62FE41151D41526D00CA389D /* InOutAnimation.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = InOutAnimation.json; sourceTree = "<group>"; };
62FE41411D41862200CA389D /* LAAnimatableLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LAAnimatableLayer.h; sourceTree = "<group>"; };
62FE41421D41862200CA389D /* LAAnimatableLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LAAnimatableLayer.m; sourceTree = "<group>"; };
62FE41BA1D42DD8500CA389D /* LAMaskLayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LAMaskLayer.h; sourceTree = "<group>"; };
62FE41BB1D42DD8500CA389D /* LAMaskLayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LAMaskLayer.m; sourceTree = "<group>"; };
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 = "<group>"; };
BC68632413866F85CEACB7EA /* libPods-LotteAnimator.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LotteAnimator.a"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,32 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LotteAnimator/LAAnimatableColorValue.m"
timestampString = "490830150.413192"
timestampString = "490656219.411516"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "152"
endingLineNumber = "152"
landmarkName = "-_colorValueFromArray:"
startingLineNumber = "38"
endingLineNumber = "38"
landmarkName = "-initWithColorValues:frameRate:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LotteAnimator/LAAnimatableColorValue.m"
timestampString = "490656219.411516"
filePath = "LotteAnimator/LAShapeCircle.m"
timestampString = "490729764.635343"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "38"
endingLineNumber = "38"
landmarkName = "-initWithColorValues:frameRate:"
startingLineNumber = "14"
endingLineNumber = "14"
landmarkName = "-initWithJSON:frameRate:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
Expand All @@ -83,13 +83,13 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LotteAnimator/LAShapePath.m"
timestampString = "490659641.355334"
filePath = "LotteAnimator/LAAnimatableScaleValue.m"
timestampString = "490740783.490737"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "23"
endingLineNumber = "23"
landmarkName = "-_mapFromJSON:frameRate:"
startingLineNumber = "82"
endingLineNumber = "82"
landmarkName = "-_buildAnimationForKeyframes:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
Expand All @@ -99,13 +99,13 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LotteAnimator/LAShapeCircle.m"
timestampString = "490729764.635343"
filePath = "LotteAnimator/LAAnimatableLayer.m"
timestampString = "490920717.958644"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "14"
endingLineNumber = "14"
landmarkName = "-initWithJSON:frameRate:"
startingLineNumber = "56"
endingLineNumber = "56"
landmarkName = "-setAnimationProgress:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
Expand All @@ -115,13 +115,13 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LotteAnimator/LAAnimatableScaleValue.m"
timestampString = "490740783.490737"
filePath = "LotteAnimator/LALayerView.m"
timestampString = "490921111.145475"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "82"
endingLineNumber = "82"
landmarkName = "-_buildAnimationForKeyframes:"
startingLineNumber = "128"
endingLineNumber = "128"
landmarkName = "-_setupViewFromModel"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
Expand All @@ -131,13 +131,13 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LotteAnimator/LALayer.m"
timestampString = "490825912.611288"
filePath = "LotteAnimator/CAAnimationGroup+LAAnimatableGroup.m"
timestampString = "490920346.033008"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "94"
endingLineNumber = "94"
landmarkName = "-_mapFromJSON:fromComposition:"
startingLineNumber = "14"
endingLineNumber = "14"
landmarkName = "+animationGroupForAnimatablePropertiesWithKeyPaths:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
Expand All @@ -147,13 +147,13 @@
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "LotteAnimator/LAAnimatableLayer.m"
timestampString = "490837507.04002"
filePath = "LotteAnimator/CAAnimationGroup+LAAnimatableGroup.m"
timestampString = "490920366.856974"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "48"
endingLineNumber = "48"
landmarkName = "-setAnimationProgress:"
startingLineNumber = "29"
endingLineNumber = "29"
landmarkName = "+animationGroupForAnimatablePropertiesWithKeyPaths:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
Expand Down
10 changes: 5 additions & 5 deletions LotteAnimator/CAAnimationGroup+LAAnimatableGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@

@implementation CAAnimationGroup (LAAnimatableGroup)

+ (nullable CAAnimationGroup *)animationGroupForAnimatablePropertiesWithKeyPaths:(nonnull NSDictionary<NSString *, id<LAAnimatableValue>> *)properties; {
+ (nullable CAAnimationGroup *)animationGroupForAnimatablePropertiesWithKeyPaths:(nonnull NSDictionary<NSString *, id<LAAnimatableValue>> *)properties {
NSMutableArray *animations = [NSMutableArray array];
NSTimeInterval duration = 0;
NSTimeInterval animduration = 0;
for (NSString *keyPath in properties.allKeys) {
id <LAAnimatableValue>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;
}
}
}

if (animations.count) {
CAAnimationGroup *animation = [CAAnimationGroup new];
animation.animations = animations;
animation.duration = duration;
animation.duration = animduration;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
return animation;
Expand Down
3 changes: 3 additions & 0 deletions LotteAnimator/LAAnimatableLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@

@interface LAAnimatableLayer : CALayer

- (instancetype)initWithDuration:(NSTimeInterval)duration NS_DESIGNATED_INITIALIZER;

@property (nonatomic, strong) NSArray *animationSublayers;
@property (nonatomic, strong) NSArray<LAAnimatableLayer *> *childLayers;
@property (nonatomic, readonly) NSTimeInterval laAnimationDuration;

@property (nonatomic, assign) BOOL loopAnimation;
@property (nonatomic, assign) BOOL autoReverseAnimation;
Expand Down
23 changes: 13 additions & 10 deletions LotteAnimator/LAAnimatableLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -44,18 +52,18 @@ - (void)setLoopAnimation:(BOOL)loopAnimation {
}

- (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) {
Expand All @@ -76,18 +84,13 @@ - (void)setAutoReverseAnimation:(BOOL)autoReverseAnimation {
}

-(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];
}


Expand Down
20 changes: 14 additions & 6 deletions LotteAnimator/LACompView.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ - (void)_viewtapped {

- (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 {
Expand All @@ -66,10 +60,24 @@ - (void)pause {
}

- (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
5 changes: 2 additions & 3 deletions LotteAnimator/LAGroupLayerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 9 additions & 5 deletions LotteAnimator/LAGroupLayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ @implementation LAGroupLayerView {
}

- (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;
Expand Down Expand Up @@ -60,21 +61,24 @@ - (void)_setupShapeGroup {
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]]) {
LAShapeRectangle *shapeRect = (LAShapeRectangle *)item;
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];
}
Expand Down
2 changes: 2 additions & 0 deletions LotteAnimator/LALayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit aa17a9d

Please sign in to comment.