0

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"];
beyowulf
  • 15,101
  • 2
  • 34
  • 40
  • also can you attach misaligned image screen shot ? – maddy May 26 '16 at 14:58
  • Instead of screenshot I have to upload video to let you know problems I am experimenting, as I have implemented dynamic gradient basing on code above. It works good, but when I try to show keyboard related to textfield, for instance, this action is very slow due to gradient. I do not know if I am allowed to upload video. – Strafoffux May 27 '16 at 08:36
  • i have had a problem like this when i was working with streching header in tableView, at that instance gradient was not streching with same velocity/ or say very slow. is your prob something like it ? This fix my problem http://stackoverflow.com/questions/17555986/cagradientlayer-not-resizing-nicely-tearing-on-rotation-video-of-issue-attac – maddy May 27 '16 at 08:44
  • Sorry man. This was not the actual problem. My problem is related to CABasicAnimation as I wrote. Anyway, I will have a try. Thank you. – Strafoffux May 30 '16 at 08:19
  • Just tried. Unfortunately no luck. Because problem was not that. Any other advice? – Strafoffux May 30 '16 at 10:27

1 Answers1

0

try to set layer.shouldRasterize = YES; and see if improve performance.

i have use this link to fix my problem may be help you CAGradientLayer, not resizing nicely, tearing on rotation. (video of issue attached) thanks

Community
  • 1
  • 1
maddy
  • 4,001
  • 8
  • 42
  • 65
  • Unfortunately, no luck with that. I have added gradientLayer.shouldRasterize = YES; but nothing changed. Any other idea? – Strafoffux May 27 '16 at 08:40