在ActionScript 3我们可以申请到这样的视觉对象的遮罩:
SomeVisualObject.mask = maskShapeObject;
我怎样才能达到同样的效果在Objective-C? 假设我有两个UIImageView
对象,我想是这样的:
imageView1.mask = imageView2;
如何使用一个UIImageView
掩盖,或夹,另外的形状?
在ActionScript 3我们可以申请到这样的视觉对象的遮罩:
SomeVisualObject.mask = maskShapeObject;
我怎样才能达到同样的效果在Objective-C? 假设我有两个UIImageView
对象,我想是这样的:
imageView1.mask = imageView2;
如何使用一个UIImageView
掩盖,或夹,另外的形状?
CALayer *maskLayer = [CALayer layer];
UIImage *maskImage = [UIImage imageNamed:@"maskImage.png"];
maskLayer.contents = (id)maskImage.CGImage;
maskLayer.bounds = (CGRect){CGPointZero, maskImage.size};
UIImageView *imageViewToMask = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
imageViewToMask.image = [UIImage imageNamed:@"image2.png"];
imageViewToMask.layer.mask = maskLayer;