拉伸绘制形状适合框架?

时间:2012-07-13 13:29:22

标签: iphone ios cocoa-touch core-graphics

我有一个应用程序,我正在绘制一个特殊的椭圆,我制作了一系列Bezier路径,如下所示:

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所以我不必手动进入我的所有点和值,并根据视图边界写它们?我知道这个形状不会那么困难,但是我有一些更复杂的形状更耗时,我宁愿避免这样做..

1 个答案:

答案 0 :(得分:0)

发现可以使用:

CGAffineTransform transform = CGAffineTransformMakeScale(frame.size.width/shapeWidth, frame.size.height/shapeHeight);
CGMutablePathRef mutablePathTransform = CGPathCreateMutableCopyByTransformingPath(mutablePath, &transform);