我正在通过以下方法对矩形的角进行四舍五入
定义一个 colouredBoxRect 并计算 x 和 y 的最小值、最大值
CGFloat coloredBoxMargin = 8;
CGFloat coloredBoxHeight = 40.0;
coloredBoxRect = CGRectMake(coloredBoxMargin, coloredBoxMargin, self.bounds.size.width-coloredBoxMargin*2, coloredBoxHeight);
CGFloat minx = CGRectGetMinX(coloredBoxRect);
CGFloat miny = CGRectGetMinY(coloredBoxRect);
CGFloat midx = CGRectGetMidX(coloredBoxRect);
CGFloat midy = CGRectGetMidY(coloredBoxRect);
CGFloat maxx = CGRectGetMaxX(coloredBoxRect);
CGFloat maxy = CGRectGetMaxY(coloredBoxRect);
然后做
CGMutablePathRef path = CGPathCreateMutable();
//Path stars here
CGPathMoveToPoint (path, NULL, midx, miny);
// Add an arc for the upper right corner
1.CGPathAddArcToPoint(path, NULL, maxx, miny, maxx, maxy, radius);
//Add an arc for the lower right corner
2.CGPathAddArcToPoint(path, NULL, maxx, maxy, minx, maxy, radius);
// Add an arc for the lower left corner
3.CGPathAddArcToPoint(path, NULL, minx, maxy, minx, miny, radius);
// Add an arc for the upper left corner
4.CGPathAddArcToPoint(path, NULL, minx, miny, maxx, miny, radius);
CGPathCloseSubpath(path);
CGContextAddPath(context, path);
其中一个签名 CGPathAddArcToPoint 是第一条和第二条切线的 x 和 y 坐标。例如为右上角添加弧)maxx+miny+maxx+maxy。这些参数现在让我感到困惑。
我试着画了一张图,发现 (maxx,miny) 不是切线的坐标。这对只是矩形右上角的坐标......
有人在这个问题上给我建议吗。欢迎所有评论在这里。谢谢