I am experiencing low performance when adding a CABasicAnimation. My app is slowing down. If I remove it, everything is smooth. I have tried to put animation in a background thread using
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^() {
});
but no luck. What can I do? Here is the code I used to create the animation. Thanks a lot!
NSArray *fromColors = gradientLayer.colors;
NSArray *toColors = [self chooseGradientColors:flag];
[gradientLayer setColors:toColors];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"colors"];
animation.fromValue = fromColors;
animation.toValue = toColors;
animation.duration = kGradientDuration;
animation.fillMode = kCAFillModeBoth;
animation.removedOnCompletion = NO;
animation.repeatCount = HUGE_VALF;
animation.autoreverses = YES;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
//Add the animation to layer
[gradientLayer addAnimation:animation forKey:@"animateGradient"];