-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
brandon_withrow
committed
Aug 4, 2017
1 parent
a45b806
commit 0cfc576
Showing
9 changed files
with
1,051 additions
and
910 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// LOTAnimationView | ||
// LottieAnimator | ||
// | ||
// Created by Brandon Withrow on 12/14/15. | ||
// Copyright © 2015 Brandon Withrow. All rights reserved. | ||
// | ||
#import <QuartzCore/QuartzCore.h> | ||
#import <Foundation/Foundation.h> | ||
|
||
@interface LOTRadialGradientLayer : CALayer | ||
|
||
@property CGPoint startPoint; | ||
@property CGPoint endPoint; | ||
|
||
@property (nonatomic, copy) NSArray *colors; | ||
@property (nonatomic, copy) NSArray<NSNumber *> *locations; | ||
@property (nonatomic, assign) BOOL isRadial; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// | ||
// LOTAnimationView | ||
// LottieAnimator | ||
// | ||
// Created by Brandon Withrow on 12/14/15. | ||
// Copyright © 2015 Brandon Withrow. All rights reserved. | ||
// | ||
|
||
#import "LOTRadialGradientLayer.h" | ||
#import "CGGeometry+LOTAdditions.h" | ||
|
||
@implementation LOTRadialGradientLayer | ||
|
||
@dynamic isRadial; | ||
@dynamic startPoint; | ||
@dynamic endPoint; | ||
@dynamic colors; | ||
@dynamic locations; | ||
|
||
+ (BOOL)needsDisplayForKey:(NSString *)key { | ||
if ([key isEqualToString:@"startPoint"] || | ||
[key isEqualToString:@"endPoint"] || | ||
[key isEqualToString:@"colors"] || | ||
[key isEqualToString:@"locations"] || | ||
[key isEqualToString:@"isRadial"]) { | ||
return YES; | ||
} | ||
return [super needsDisplayForKey:key]; | ||
} | ||
|
||
- (id)actionForKey:(NSString *)key { | ||
if ([key isEqualToString:@"startPoint"] || | ||
[key isEqualToString:@"endPoint"] || | ||
[key isEqualToString:@"colors"] || | ||
[key isEqualToString:@"locations"] || | ||
[key isEqualToString:@"isRadial"]) { | ||
CABasicAnimation *theAnimation = [CABasicAnimation animationWithKeyPath:key]; | ||
theAnimation.fromValue = [self.presentationLayer valueForKey:key]; | ||
return theAnimation; | ||
} | ||
return [super actionForKey:key]; | ||
} | ||
|
||
- (void)drawInContext:(CGContextRef)ctx { | ||
NSInteger numberOfLocations = self.locations.count; | ||
NSInteger numbOfComponents = 0; | ||
CGColorSpaceRef colorSpace = NULL; | ||
|
||
if (self.colors.count) { | ||
CGColorRef colorRef = (__bridge CGColorRef)[self.colors objectAtIndex:0]; | ||
numbOfComponents = CGColorGetNumberOfComponents(colorRef); | ||
colorSpace = CGColorGetColorSpace(colorRef); | ||
} | ||
|
||
CGPoint origin = self.startPoint; | ||
CGFloat radius = LOT_PointDistanceFromPoint(self.startPoint, self.endPoint); | ||
|
||
CGFloat gradientLocations[numberOfLocations]; | ||
CGFloat gradientComponents[numberOfLocations * numbOfComponents]; | ||
|
||
for (NSInteger locationIndex = 0; locationIndex < numberOfLocations; locationIndex++) { | ||
|
||
gradientLocations[locationIndex] = [self.locations[locationIndex] floatValue]; | ||
const CGFloat *colorComponents = CGColorGetComponents((__bridge CGColorRef)self.colors[locationIndex]); | ||
|
||
for (NSInteger componentIndex = 0; componentIndex < numbOfComponents; componentIndex++) { | ||
gradientComponents[numbOfComponents * locationIndex + componentIndex] = colorComponents[componentIndex]; | ||
} | ||
} | ||
|
||
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, gradientComponents, gradientLocations, numberOfLocations); | ||
|
||
if (self.isRadial) { | ||
CGContextDrawRadialGradient(ctx, gradient, origin, 0, origin, radius, kCGGradientDrawsAfterEndLocation); | ||
} else { | ||
CGContextDrawLinearGradient(ctx, gradient, self.startPoint, self.endPoint, kCGGradientDrawsAfterEndLocation); | ||
} | ||
|
||
CGGradientRelease(gradient); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters