您好我正在使用核心动画和核心图形。我正在绘制一条不是矩形或圆形或椭圆形的路径,所以我不能给该路径框架。现在我想将渐变颜色设置为路径。但是我想需要框架,我不能给。这是我的道路代码:
CGPoint point1 = CGPointMake(120.0f, 50.0f);
CGPoint point2 = CGPointMake(240.0f, 150.0f);
CGPoint point3 = CGPointMake(360.0f, 50.0f);
CGPoint point4 = CGPointMake(480.0f+50/2.0, 100.0f);
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, 50, 50);
CGPathAddCurveToPoint(curvedPath, NULL, point1.x, 50, point1.x, 50, point1.x, point1.y);
CGPathAddCurveToPoint(curvedPath, NULL, point2.x, 50, point2.x, 50, point2.x, point2.y);
CGPathAddCurveToPoint(curvedPath, NULL, point3.x, 50, point3.x, 50, point3.x, point3.y);
CGPathAddCurveToPoint(curvedPath, NULL, point4.x, 50, point4.x, 50, point4.x, point4.y);
CGPathCloseSubpath(curvedPath);
return curvedPath;
答案 0 :(得分:1)
使用CGPathGetPathBoundingBox
。如果gradientLayer
是shapeLayer
的子图层或遮罩图层,请尝试以下操作:
gradientLayer.frame = CGPathGetPathBoundingBox(shapeLayer.path);