CABasicAnimation慢慢降低我的应用程序

时间:2016-05-26 14:03:07

标签: ios core-animation

添加CABasicAnimation时,我遇到的性能很低。我的应用程序正在放慢速度。如果我将其移除,一切都很顺利。 我试图使用

将动画放在后台线程中
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^() {
});

但没有运气。 我能做什么? 这是我用来创建动画的代码。 非常感谢!

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"];

1 个答案:

答案 0 :(得分:0)

尝试设置layer.shouldRasterize = YES;并查看是否提高效果。

我使用此链接修复我的问题可能会对您有所帮助CAGradientLayer, not resizing nicely, tearing on rotation. (video of issue attached)谢谢