1

我有一个应用程序,我正在绘制一个特殊的椭圆,我通过一系列贝塞尔路径制作了如下:

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);

CGMutablePathRef pPath_0 = CGPathCreateMutable();
CGPathMoveToPoint(pPath_0, NULL, 515.98,258.24);
CGPathAddCurveToPoint(pPath_0, NULL, 515.98,435.61,415.54,515.98,258.24,515.98);
CGPathAddCurveToPoint(pPath_0, NULL, 100.94,515.98,0.50,435.61,0.50,258.24);
CGPathAddCurveToPoint(pPath_0, NULL, 0.50,80.86,100.94,0.50,258.24,0.50);
CGPathAddCurveToPoint(pPath_0, NULL, 415.54,0.50,515.98,80.86,515.98,258.24);
CGPathCloseSubpath(pPath_0);
CGContextSetRGBFillColor(context, 1.0000, 1.0000, 1.0000, 1.0000);

CGContextSetRGBStrokeColor(context,0.0000,0.0000,0.0000,1.0000);
CGContextSetLineWidth(context, 1);
CGContextSetMiterLimit(context, 10.0000);

CGContextAddPath(context, pPath_0);
CGContextDrawPath(context, kCGPathFillStroke);
CGPathRelease(pPath_0);
CGContextRestoreGState(context);

我想知道,在核心图形中有什么方法可以让我采用我刚刚创建的形状并水平和垂直拉伸它,使其完美地适合其视图框架?IE,所以我不必手动进入我的所有点和值并根据视图边界编写它们?我知道这种形状不会那么困难,但我有一些更复杂的形状更耗时,我宁愿避免这样做..

4

1 回答 1

0

发现可以使用:

CGAffineTransform transform = CGAffineTransformMakeScale(frame.size.width/shapeWidth, frame.size.height/shapeHeight);
CGMutablePathRef mutablePathTransform = CGPathCreateMutableCopyByTransformingPath(mutablePath, &transform);
于 2012-07-27T22:15:54.837 回答