-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathFRDLivelyButton.m
executable file
·460 lines (376 loc) · 21.2 KB
/
FRDLivelyButton.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
//
// FRDLivelyButton.h.m
// FRDLivelyButton.h
//
// Created by Sebastien Windal on 2/24/14.
// MIT license. See the LICENSE file distributed with this work.
//
#import "FRDLivelyButton.h"
NSString *const kFRDLivelyButtonHighlightScale = @"kFRDLivelyButtonHighlightScale";
NSString *const kFRDLivelyButtonLineWidth = @"kFRDLivelyButtonLineWidth";
NSString *const kFRDLivelyButtonColor = @"kFRDLivelyButtonColor";
NSString *const kFRDLivelyButtonHighlightedColor = @"kFRDLivelyButtonHighlightedColor";
NSString *const kFRDLivelyButtonHighlightAnimationDuration = @"kFRDLivelyButtonHighlightAnimationDuration";
NSString *const kFRDLivelyButtonUnHighlightAnimationDuration = @"kFRDLivelyButtonUnHighlightAnimationDuration";
NSString *const kFRDLivelyButtonStyleChangeAnimationDuration = @"kFRDLivelyButtonStyleChangeAnimationDuration";
@interface FRDLivelyButton()
@property (nonatomic) kFRDLivelyButtonStyle buttonStyle;
@property (nonatomic) CGFloat dimension;
@property (nonatomic) CGPoint offset;
@property (nonatomic) CGPoint centerPoint;
@property (nonatomic, strong) CAShapeLayer *circleLayer;
@property (nonatomic, strong) CAShapeLayer *line1Layer;
@property (nonatomic, strong) CAShapeLayer *line2Layer;
@property (nonatomic, strong) CAShapeLayer *line3Layer;
@property (nonatomic, strong) NSArray *shapeLayers;
@end
#define GOLDEN_RATIO 1.618
@implementation FRDLivelyButton
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self commonInitializer];
}
return self;
}
-( id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self commonInitializer];
}
return self;
}
-(void) commonInitializer
{
self.line1Layer = [[CAShapeLayer alloc] init];
self.line2Layer = [[CAShapeLayer alloc] init];
self.line3Layer = [[CAShapeLayer alloc] init];
self.circleLayer = [[CAShapeLayer alloc] init];
self.options = [FRDLivelyButton defaultOptions];
[@[ self.line1Layer, self.line2Layer, self.line3Layer, self.circleLayer ] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
CAShapeLayer *layer = obj;
layer.fillColor = [UIColor clearColor].CGColor;
layer.anchorPoint = CGPointMake(0.0, 0.0);
layer.lineJoin = kCALineJoinRound;
layer.lineCap = kCALineCapRound;
layer.contentsScale = self.layer.contentsScale;
// initialize with an empty path so we can animate the path w/o having to check for NULLs.
CGPathRef dummyPath = CGPathCreateMutable();
layer.path = dummyPath;
CGPathRelease(dummyPath);
[self.layer addSublayer:layer];
}];
[self addTarget:self action:@selector(showHighlight) forControlEvents:UIControlEventTouchDown];
[self addTarget:self action:@selector(showUnHighlight) forControlEvents:UIControlEventTouchUpInside];
[self addTarget:self action:@selector(showUnHighlight) forControlEvents:UIControlEventTouchUpOutside];
// in case the button is not square, the offset will be use to keep our CGPath's centered in it.
double width = CGRectGetWidth(self.frame) - (self.contentEdgeInsets.left + self.contentEdgeInsets.right);
double height = CGRectGetHeight(self.frame) - (self.contentEdgeInsets.top + self.contentEdgeInsets.bottom);
self.dimension = MIN(width, height);
self.offset = CGPointMake((CGRectGetWidth(self.frame) - self.dimension) / 2.0f,
(CGRectGetHeight(self.frame) - self.dimension) / 2.0f);
self.centerPoint = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
}
-(void) setOptions:(NSDictionary *)options
{
_options = options;
[@[ self.line1Layer, self.line2Layer, self.line3Layer, self.circleLayer ] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
CAShapeLayer *layer = obj;
layer.lineWidth = [[self valueForOptionKey:kFRDLivelyButtonLineWidth] floatValue];
layer.strokeColor = [[self valueForOptionKey:kFRDLivelyButtonColor] CGColor];
}];
}
-(id) valueForOptionKey:(NSString *)key
{
if (self.options[key]) {
return self.options[key];
}
return [FRDLivelyButton defaultOptions][key];
}
-(NSArray *) shapeLayers
{
if (_shapeLayers == nil) {
_shapeLayers = @[ self.circleLayer,
self.line1Layer,
self.line2Layer,
self.line3Layer ];
}
return _shapeLayers;
}
+(NSDictionary *) defaultOptions
{
return @{
kFRDLivelyButtonColor: [UIColor blackColor],
kFRDLivelyButtonHighlightedColor: [UIColor lightGrayColor],
kFRDLivelyButtonHighlightAnimationDuration: @(0.1),
kFRDLivelyButtonHighlightScale: @(0.9),
kFRDLivelyButtonLineWidth: @(1.0),
kFRDLivelyButtonUnHighlightAnimationDuration: @(0.15),
kFRDLivelyButtonStyleChangeAnimationDuration: @(0.3)
};
}
-(CGAffineTransform) transformWithScale:(CGFloat)scale
{
CGAffineTransform transform = CGAffineTransformMakeTranslation((self.dimension + 2 * self.offset.x) * ((1-scale)/2.0f),
(self.dimension + 2 * self.offset.y) * ((1-scale)/2.0f));
return CGAffineTransformScale(transform, scale, scale);
}
// you are responsible for releasing the return CGPath
-(CGPathRef) createCenteredCircleWithRadius:(CGFloat)radius
{
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, self.centerPoint.x + radius, self.centerPoint.y);
// note: if clockwise is set to true, the circle will not draw on an actual device,
// event hough it is fine on the simulator...
CGPathAddArc(path, NULL, self.centerPoint.x, self.centerPoint.y, radius, 0, 2 * M_PI, false);
return path;
}
// you are responsible for releasing the return CGPath
-(CGPathRef) createCenteredLineWithRadius:(CGFloat)radius angle:(CGFloat)angle offset:(CGPoint)offset
{
CGMutablePathRef path = CGPathCreateMutable();
float c = cosf(angle);
float s = sinf(angle);
CGPathMoveToPoint(path, NULL,
self.centerPoint.x + offset.x + radius * c,
self.centerPoint.y + offset.y + radius * s);
CGPathAddLineToPoint(path, NULL,
self.centerPoint.x + offset.x - radius * c,
self.centerPoint.y + offset.y - radius * s);
return path;
}
-(CGPathRef) createLineFromPoint:(CGPoint)p1 toPoint:(CGPoint)p2
{
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, self.offset.x + p1.x, self.offset.y + p1.y);
CGPathAddLineToPoint(path, NULL, self.offset.x + p2.x, self.offset.y + p2.y);
return path;
}
-(void) setStyle:(kFRDLivelyButtonStyle)style animated:(BOOL)animated
{
self.buttonStyle = style;
CGPathRef newCirclePath = NULL;
CGPathRef newLine1Path = NULL;
CGPathRef newLine2Path = NULL;
CGPathRef newLine3Path = NULL;
CGFloat newCircleAlpha = 0.0f;
CGFloat newLine1Alpha = 0.0f;
// first compute the new paths for our 4 layers.
if (style == kFRDLivelyButtonStyleHamburger) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/2.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 1.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/2.0f angle:0 offset:CGPointMake(0, -self.dimension/2.0f/GOLDEN_RATIO)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/2.0f angle:0 offset:CGPointMake(0, self.dimension/2.0f/GOLDEN_RATIO)];
} else if (style == kFRDLivelyButtonStylePlus) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/20.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 0.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/2.0f angle:+M_PI_2 offset:CGPointMake(0, 0)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/2.0f angle:0 offset:CGPointMake(0, 0)];
} else if (style == kFRDLivelyButtonStyleCirclePlus) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/2.0f];
newCircleAlpha = 1.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/20.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 0.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/2.0f/GOLDEN_RATIO angle:M_PI_2 offset:CGPointMake(0, 0)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/2.0f/GOLDEN_RATIO angle:0 offset:CGPointMake(0, 0)];
} else if (style == kFRDLivelyButtonStyleClose) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/20.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 0.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/2.0f angle:+M_PI_4 offset:CGPointMake(0, 0)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/2.0f angle:-M_PI_4 offset:CGPointMake(0, 0)];
} else if (style == kFRDLivelyButtonStyleCircleClose) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/2.0f];
newCircleAlpha = 1.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/20.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 0.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/2.0f/GOLDEN_RATIO angle:+M_PI_4 offset:CGPointMake(0, 0)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/2.0f/GOLDEN_RATIO angle:-M_PI_4 offset:CGPointMake(0, 0)];
} else if (style == kFRDLivelyButtonStyleCaretUp) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/20.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 0.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line2Layer.lineWidth/2.0f angle:M_PI_4 offset:CGPointMake(self.dimension/6.0f,0.0f)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line3Layer.lineWidth/2.0f angle:3*M_PI_4 offset:CGPointMake(-self.dimension/6.0f,0.0f)];
} else if (style == kFRDLivelyButtonStyleCaretDown) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/20.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 0.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line2Layer.lineWidth/2.0f angle:-M_PI_4 offset:CGPointMake(self.dimension/6.0f,0.0f)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line3Layer.lineWidth/2.0f angle:-3*M_PI_4 offset:CGPointMake(-self.dimension/6.0f,0.0f)];
} else if (style == kFRDLivelyButtonStyleCaretLeft) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/20.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 0.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line2Layer.lineWidth/2.0f angle:-3*M_PI_4 offset:CGPointMake(0.0f,self.dimension/6.0f)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line3Layer.lineWidth/2.0f angle:3*M_PI_4 offset:CGPointMake(0.0f,-self.dimension/6.0f)];
} else if (style == kFRDLivelyButtonStyleCaretRight) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/20.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 0.0f;
newLine2Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line2Layer.lineWidth/2.0f angle:-M_PI_4 offset:CGPointMake(0.0f,self.dimension/6.0f)];
newLine3Path = [self createCenteredLineWithRadius:self.dimension/4.0f - self.line3Layer.lineWidth/2.0f angle:M_PI_4 offset:CGPointMake(0.0f,-self.dimension/6.0f)];
} else if (style == kFRDLivelyButtonStyleArrowLeft) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/2.0f angle:M_PI offset:CGPointMake(0, 0)];
newLine1Alpha = 1.0f;
newLine2Path = [self createLineFromPoint:CGPointMake(0, self.dimension/2.0f)
toPoint:CGPointMake(self.dimension/2.0f/GOLDEN_RATIO, self.dimension/2+self.dimension/2.0f/GOLDEN_RATIO)];
newLine3Path = [self createLineFromPoint:CGPointMake(0, self.dimension/2.0f)
toPoint:CGPointMake(self.dimension/2.0f/GOLDEN_RATIO, self.dimension/2-self.dimension/2.0f/GOLDEN_RATIO)];
} else if (style == kFRDLivelyButtonStyleArrowRight) {
newCirclePath = [self createCenteredCircleWithRadius:self.dimension/20.0f];
newCircleAlpha = 0.0f;
newLine1Path = [self createCenteredLineWithRadius:self.dimension/2.0f angle:0 offset:CGPointMake(0, 0)];
newLine1Alpha = 1.0f;
newLine2Path = [self createLineFromPoint:CGPointMake(self.dimension, self.dimension/2.0f)
toPoint:CGPointMake(self.dimension - self.dimension/2.0f/GOLDEN_RATIO, self.dimension/2+self.dimension/2.0f/GOLDEN_RATIO)];
newLine3Path = [self createLineFromPoint:CGPointMake(self.dimension, self.dimension/2.0f)
toPoint:CGPointMake(self.dimension - self.dimension/2.0f/GOLDEN_RATIO, self.dimension/2-self.dimension/2.0f/GOLDEN_RATIO)];
} else {
NSAssert(FALSE, @"unknown type");
}
NSTimeInterval duration = [[self valueForOptionKey:kFRDLivelyButtonStyleChangeAnimationDuration] floatValue];
// animate all the layer path and opacity
if (animated) {
{
CABasicAnimation *circleAnim = [CABasicAnimation animationWithKeyPath:@"path"];
circleAnim.removedOnCompletion = NO;
circleAnim.duration = duration;
circleAnim.fromValue = (__bridge id)self.circleLayer.path;
circleAnim.toValue = (__bridge id)newCirclePath;
[circleAnim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[self.circleLayer addAnimation:circleAnim forKey:@"animateCirclePath"];
}
{
CABasicAnimation *circleAlphaAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
circleAlphaAnim.removedOnCompletion = NO;
circleAlphaAnim.duration = duration;
circleAlphaAnim.fromValue = @(self.circleLayer.opacity);
circleAlphaAnim.toValue = @(newCircleAlpha);
[circleAlphaAnim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[self.circleLayer addAnimation:circleAlphaAnim forKey:@"animateCircleOpacityPath"];
}
{
CABasicAnimation *line1Anim = [CABasicAnimation animationWithKeyPath:@"path"];
line1Anim.removedOnCompletion = NO;
line1Anim.duration = duration;
line1Anim.fromValue = (__bridge id)self.line1Layer.path;
line1Anim.toValue = (__bridge id)newLine1Path;
[line1Anim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[self.line1Layer addAnimation:line1Anim forKey:@"animateLine1Path"];
}
{
CABasicAnimation *line1AlphaAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
line1AlphaAnim.removedOnCompletion = NO;
line1AlphaAnim.duration = duration;
line1AlphaAnim.fromValue = @(self.line1Layer.opacity);
line1AlphaAnim.toValue = @(newLine1Alpha);
[line1AlphaAnim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[self.line1Layer addAnimation:line1AlphaAnim forKey:@"animateLine1OpacityPath"];
}
{
CABasicAnimation *line2Anim = [CABasicAnimation animationWithKeyPath:@"path"];
line2Anim.removedOnCompletion = NO;
line2Anim.duration = duration;
line2Anim.fromValue = (__bridge id)self.line2Layer.path;
line2Anim.toValue = (__bridge id)newLine2Path;
[line2Anim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[self.line2Layer addAnimation:line2Anim forKey:@"animateLine2Path"];
}
{
CABasicAnimation *line3Anim = [CABasicAnimation animationWithKeyPath:@"path"];
line3Anim.removedOnCompletion = NO;
line3Anim.duration = duration;
line3Anim.fromValue = (__bridge id)self.line3Layer.path;
line3Anim.toValue = (__bridge id)newLine3Path;
[line3Anim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[self.line3Layer addAnimation:line3Anim forKey:@"animateLine3Path"];
}
}
self.circleLayer.path = newCirclePath;
self.circleLayer.opacity = newCircleAlpha;
self.line1Layer.path = newLine1Path;
self.line1Layer.opacity = newLine1Alpha;
self.line2Layer.path = newLine2Path;
self.line3Layer.path = newLine3Path;
CGPathRelease(newCirclePath);
CGPathRelease(newLine1Path);
CGPathRelease(newLine2Path);
CGPathRelease(newLine3Path);
}
// animate button pressed event.
-(void) showHighlight
{
float highlightScale = [[self valueForOptionKey:kFRDLivelyButtonHighlightScale] floatValue];
[self.shapeLayers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[obj setStrokeColor:[[self valueForOptionKey:kFRDLivelyButtonHighlightedColor] CGColor]];
CAShapeLayer *layer = obj;
CGAffineTransform transform = [self transformWithScale:highlightScale];
CGPathRef scaledPath = CGPathCreateMutableCopyByTransformingPath(layer.path, &transform);
CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"path"];
anim.duration = [[self valueForOptionKey:kFRDLivelyButtonHighlightAnimationDuration] floatValue];
anim.removedOnCompletion = NO;
anim.fromValue = (__bridge id) layer.path;
anim.toValue = (__bridge id) scaledPath;
[anim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[layer addAnimation:anim forKey:nil];
layer.path = scaledPath;
CGPathRelease(scaledPath);
}];
}
// animate button release events i.e. touch up inside or outside.
-(void) showUnHighlight
{
float unHighlightScale = 1/[[self valueForOptionKey:kFRDLivelyButtonHighlightScale] floatValue];
[self.shapeLayers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[obj setStrokeColor:[[self valueForOptionKey:kFRDLivelyButtonColor] CGColor]];
CAShapeLayer *layer = obj;
CGPathRef path = layer.path;
CGAffineTransform transform = [self transformWithScale:unHighlightScale];
CGPathRef finalPath = CGPathCreateMutableCopyByTransformingPath(path, &transform);
CGAffineTransform uptransform = [self transformWithScale:unHighlightScale * 1.07];
CGPathRef scaledUpPath = CGPathCreateMutableCopyByTransformingPath(path, &uptransform);
CGAffineTransform downtransform = [self transformWithScale:unHighlightScale * 0.97];
CGPathRef scaledDownPath = CGPathCreateMutableCopyByTransformingPath(path, &downtransform);
NSArray *values = @[
(__bridge id) layer.path,
(id) CFBridgingRelease(scaledUpPath),
(id) CFBridgingRelease(scaledDownPath),
(__bridge id) finalPath
];
NSArray *times = @[ @(0.0), @(0.85), @(0.93), @(1.0) ];
CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"path"];
anim.duration = [[self valueForOptionKey:kFRDLivelyButtonUnHighlightAnimationDuration] floatValue];;
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
anim.removedOnCompletion = NO;
anim.values = values;
anim.keyTimes = times;
[layer addAnimation:anim forKey:nil];
layer.path = finalPath;
CGPathRelease(finalPath);
}];
return;
}
-(void) dealloc
{
for (CALayer* layer in [self.layer sublayers]) {
[layer removeAllAnimations];
}
[self.layer removeAllAnimations];
self.shapeLayers = nil;
}
@end