我在一个更大的 CAShapelayer 内有 3 个 CAShapelayers。比如说矩形,一个大矩形内的三角形,所有这些 CAShapelayers 都绘制在一个图像上。我需要用图案图像填充更大的矩形,但不需要填充所有其他 2 个形状。我试过屏蔽,偶数规则。请帮忙。目前我得到的完全相反。填充内层而不是外层这就是我正在做的
// mask layer is the outer layer
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.fillRule = kCAFillRuleEvenOdd;
maskLayer.frame = self.view.frame;
//inner layer1
CAShapeLayer *maskSubLayer1 = [CAShapeLayer layer];
maskSubLayer1.fillRule = kCAFillRuleEvenOdd;
maskSubLayer1.frame = self.view.frame;
//inner layer 2
CAShapeLayer *maskSubLayer2 = [CAShapeLayer layer];
maskSubLayer2.fillRule = kCAFillRuleEvenOdd;
maskSubLayer2.frame = self.view.frame;
//shapelayer and shapelayer 2 are the exact layer that are drawn inside
// add the paths to sublayers of the mask
maskSubLayer1.path = shapeLayer.path;
maskSubLayer2.path = shapeLayer2.path;
[maskLayer addSublayer:maskSubLayer1];
[maskLayer addSublayer:maskSubLayer2];
// masking the outer layer
biggershapeLayer.mask = maskLayer;
[biggershapeLayer setFillColor:[UIColor colorWithPatternImage:[UIImage imageNamed:[imagesArray objectAtIndex:indexPath.row]]].CGColor];
[self.view.layer addSublayer:biggershapeLayer];
*******************************************
* *
* *
* ******* ****** *
* ******** ****** *
* ******* ****** *
* ******* ****** *
* *
*******************************************
This is the current result I want the exact opposite.