本文介绍了CAGradientLayer不够流畅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的 UIView 的每个背景做 CAGradientLayer ,但我遇到了一个小问题。渐变似乎不够平滑。颜色之间的过渡将呈现。你可以在这张图片中看到它。

I'm doing a CAGradientLayer for every background of my UIViews, but I have a small problem. The gradient doesn't seem that smooth enough. The transition between the colors are to present. You can see it in this picture.

这就是我在UIView初始化程序中实现此渐变的方法。

This is how I implemented this gradient in the initializer of my UIView.

CAGradientLayer *layer = [CAGradientLayer layer];
layer.colors = [NSArray arrayWithObjects:
                (id)[[UIColor darkKinepolisColor] CGColor],
                (id)[[UIColor lightKinepolisColor] CGColor],
                (id)[[UIColor lightKinepolisColor] CGColor],
                (id)[[UIColor darkKinepolisColor] CGColor],
                nil];
layer.locations = [NSArray arrayWithObjects:
                   [NSNumber numberWithFloat:0],
                   [NSNumber numberWithFloat:0.4],
                   [NSNumber numberWithFloat:0.6],
                   [NSNumber numberWithFloat:1],
                   nil];
layer.startPoint = CGPointMake(0, 0);
layer.frame = self.layer.bounds;
layer.endPoint = CGPointMake(1, 1);
layer.contentsGravity = kCAGravityResize;
[self.layer addSublayer:layer];

优秀的开发人员可以帮我解决这个问题吗?谢谢!

Could you, fine developers, help me with this problem? Thanks!

推荐答案

从我所见,CAGradientLayer不支持抖动,但CGGradient支持抖动。请参阅我的答案。另请参阅其他答案,例如关于使用CGGradient。

From what I've seen CAGradientLayer does not support dithering, but CGGradient does. See my answer here. Also see the other answers for example on using CGGradient.

这篇关于CAGradientLayer不够流畅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 15:51