两个图像上下文不在同一位置,我希望其中一个图像上下文根据它们的交叉区域被遮挡
答案 0 :(得分:0)
UIImage *image1, *image2;
/* .... */
CALayer *maskLayer = [[CALayer alloc] init];
[maskLayer setFrame:[image1 convertRect:image2.bounds fromView:image2]];
maskLayer.backgroundColor=[[UIColor blackColor] CGColor];
image1.layer.mask=maskLayer;
[maskLayer release];
maskLayer = [[CALayer alloc] init];
[maskLayer setFrame:[image2 convertRect:image1.bounds fromView:image1]];
maskLayer.backgroundColor=[[UIColor blackColor] CGColor];
image2.layer.mask=maskLayer;
[maskLayer release];