在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;