//!Add animation to each sublayer in effect layer
- (void)addSublayersAnimationNeedReverse:(CAAnimation*)anim forKey:(NSString*)key forLayer:(CALayer*)layer reverseAnimation:(BOOL)reverse totalDuration:(CGFloat)totalDuration{
NSArray *sublayers =  layer.sublayers;
NSInteger sublayersCount = sublayers.count;

void (^setBeginTime)(CAAnimation*, NSInteger) = ^(CAAnimation *subAnim, NSInteger sublayerIdx){
CGFloat instanceDelay = [[subAnim valueForKey:@"instanceDelay"] floatValue];
NSInteger orderType = [[subAnim valueForKey:@"instanceOrder"] integerValue];
switch (orderType) {
case 0: subAnim.beginTime += sublayerIdx * instanceDelay; break;
case 1: subAnim.beginTime += (sublayersCount - sublayerIdx - 1) * instanceDelay; break;
case 2: {
CGFloat middleIdx     = sublayersCount/2.0f;
CGFloat begin         = fabs((middleIdx - sublayerIdx)) * instanceDelay ;
subAnim.beginTime     += begin; break;
}
case 3: {
CGFloat middleIdx     = sublayersCount/2.0f;
CGFloat begin         = (middleIdx - fabs((middleIdx - sublayerIdx))) * instanceDelay ;
subAnim.beginTime     += begin; break;
}
case 4: {
//Add yours here
}
default:
break;
}
};

[sublayers enumerateObjectsWithOptions:0 usingBlock:^(CALayer *sublayer, NSUInteger idx, BOOL *stop) {
if ([anim isKindOfClass:[CAAnimationGroup class]]) {
CAAnimationGroup *groupAnim      = (CAAnimationGroup*)anim.copy;
NSMutableArray *newSubAnimations = [NSMutableArray arrayWithCapacity:groupAnim.animations.count];
for (CABasicAnimation *subAnim in groupAnim.animations) {
[newSubAnimations addObject:subAnim.copy];
}

groupAnim.animations = newSubAnimations;
NSArray *animations  = [(CAAnimationGroup*)groupAnim animations];
for (CABasicAnimation *sub in animations) {
setBeginTime(sub, idx);

//Reverse animation if needed
if (reverse) [self reverseAnimation:sub totalDuration:totalDuration];
}
[sublayer addAnimation:groupAnim forKey:key];
}
else{
CABasicAnimation *copiedAnim = anim.copy;
setBeginTime(copiedAnim, idx);
[sublayer addAnimation:copiedAnim forKey:key];
}
}];
}
