Objective c uiimageview上的Alpha遮罩渐变

Objective c uiimageview上的Alpha遮罩渐变,objective-c,uiimageview,quartz-graphics,alpha,Objective C,Uiimageview,Quartz Graphics,Alpha,我想能够添加一个阿尔法梯度到图像的边缘,使其“淡入”到下一个图像。下面的图片解释了我要做的事情 你知道怎么做吗?我对图形上下文没有太多的经验,这就是我在这里寻求帮助的原因。您可以检查此代码并发布结果 UIImage* first = [[UIImage alloc]initWithContentsOfFile:@"firstImagePath"]; UIImage* second = [[UIImage alloc]initWithContentsOfFile:@"secondImagePat

我想能够添加一个阿尔法梯度到图像的边缘,使其“淡入”到下一个图像。下面的图片解释了我要做的事情


你知道怎么做吗?我对图形上下文没有太多的经验,这就是我在这里寻求帮助的原因。

您可以检查此代码并发布结果

UIImage* first = [[UIImage alloc]initWithContentsOfFile:@"firstImagePath"];
UIImage* second = [[UIImage alloc]initWithContentsOfFile:@"secondImagePath"];
CGSize sizeToSet;
int mergeArea = 200;
sizeToSet.width = first.size.width + second.size.width - mergeArea;
sizeToSet.height = first.size.height;

UIGraphicsBeginImageContext(sizeToSet);

[first drawAtPoint:CGPointMake(0, 0)];
[second drawAtPoint:CGPointMake(first.size.width - mergeArea, 0) blendMode:kCGBlendModeLuminosity alpha:1.0f];

UIImageView* imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
[imageView setCenter:self.view.center];
[imageView setImage:UIGraphicsGetImageFromCurrentImageContext()];

UIGraphicsEndImageContext();

[[self view]addSubview:imageView];

[imageView release];
[first release];
[second release];

这个解决方案不起作用。图像只是重叠,重叠区域的颜色略有变化。谢谢你的评论。嗨,你找到这个问题的答案了吗?我被一个类似的东西卡住了。我是通过操纵uiview的图层来完成的!保留底部图像(在本例中为右侧图像)。接下来,创建一个位置为[0,95,1]的CAGradientLayer(在本例中)。对于颜色,像[白色,白色,透明]这样的东西就可以了。接下来,将该层设置为uiimageview的遮罩。