ActionScript 3 中,我们可以将 mask 应用于视觉对象,如下所示:

SomeVisualObject.mask = maskShapeObject;

如何在 Objective-C 中获得相似的结果?假设我有两个UIImageView对象,我想要这样的东西:
imageView1.mask = imageView2;

如何使用一种UIImageView遮盖另一种ojit_code或剪切其形状?

最佳答案

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;

关于ios - 在Objective-C中 mask View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11502539/

10-11 21:01