我有一个带有一些UICollectionViewCells的UICollectionView。单元格应该相互重叠,但也可以根据它们的位置淡入淡出一点。看到下面的结果:
如何避免这些角变得可见? (顶部介于3和4之间,或介于4和5之间,或者最右侧介于5和6之间)。它们应该重叠,但这不会影响图像。
答案 0 :(得分:1)
为了创建淡入淡出效果,我将使用这样的叠加层:
我会给你一个例子来更好地说明:
private UIImage baseImage;
private UIImage ChangeImageColor(UIImage image, nfloat alpha, UIColor color)
{
var alphaColor = color.ColorWithAlpha(alpha);
if(baseImage == null)
{
baseImage = image;
}
else
{
image = baseImage;
}
UIGraphics.BeginImageContextWithOptions(image.Size, false, UISCreen.MainScreen.Scale);
var context = UIGraphics.GetCurrentContext();
alphaColor.SetFill();
context.TranslateCTM(0, image.Size.Height);
context.ScaleCTM(new nfloat(1.0), new nfloat(-1.0));
context.SetBlendMode(CGBlendMode.Lighten);
var rect = new CGRect(0, 0, image.Size.Width, image.Size.Height);
context.DrawImage(rect, image.CGImage);
context.SetBlendMode(CGBlendMode.SourceAtop);
context.AddRect(rect);
context.DrawPath(CGPathDrawingMode.Fill);
image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return image;
}