Ios 使用alpha绘制CGG渐变效果不佳

Ios 使用alpha绘制CGG渐变效果不佳,ios,core-graphics,Ios,Core Graphics,我最终尝试创建一个渐变叠加,从60%的黑色渐变到清晰,再到40%的黑色。结果有很多条带,所以我只是想先让两种颜色正常工作 在第一种情况下,我尝试从纯黑色到纯白色的渐变,它绘制得非常完美 在第二种情况下,我放置了一个从100%黑色到透明的渐变,背景为纯色灰色。乐队真的很糟糕 生成此渐变的代码如下所示: // Draw the overlay gradient CGContextTranslateCTM(context, 0.0, size.height); CGContextScaleCTM(

我最终尝试创建一个渐变叠加,从60%的黑色渐变到清晰,再到40%的黑色。结果有很多条带,所以我只是想先让两种颜色正常工作

在第一种情况下,我尝试从纯黑色到纯白色的渐变,它绘制得非常完美

在第二种情况下,我放置了一个从100%黑色到透明的渐变,背景为纯色灰色。乐队真的很糟糕

生成此渐变的代码如下所示:

// Draw the overlay gradient
CGContextTranslateCTM(context, 0.0, size.height);
CGContextScaleCTM(context, 1.0, -1.0);

UIColor *firstColor = [UIColor colorWithWhite:0.0 alpha:1.0];       
UIColor *secondColor = [UIColor clearColor];
CGContextSetBlendMode(context, kCGBlendModeSourceAtop);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

NSArray *coreGraphicsColors = @[(id)firstColor.CGColor, (id)secondColor.CGColor];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)coreGraphicsColors, 0);

static const CGFloat standardDegree = 270;
const CGFloat degree = (standardDegree * M_PI / 180);
const CGPoint center = CGPointMake(size.width / 2, size.height / 2);
const CGPoint startPoint = CGPointMake(center.x - cos(degree) * size.width / 2, center.y - sin(degree) * size.height / 2);
const CGPoint endPoint = CGPointMake(center.x + cos(degree) * size.width / 2, center.y + sin(degree) * size.height / 2);
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);

CGGradientRelease(gradient);
CGColorSpaceRelease(colorSpace);

是否有人有创建这些部分透明的渐变的经验/技巧?我尝试过改变一些东西,比如位置和颜色空间,但都没有效果。

这可能会对你有所帮助

你能发布一张结果的图片吗?@Fonix该代码生成第二个屏幕截图。哦,对不起,由于某种原因,这些图片不想为我加载