问题
I have an app where I'm drawing a special ellipse I made a via series of Bezier Paths as follows:
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);
I am wondering, is there any way in core graphics where I can take the shape I just created and stretch it both horizontally and vertically so that it fits perfectly in its views frame? IE so I don't have to manually go into all my points and values and write them in terms of the view bounds? I know for this shape it wouldn't be that difficult, but I have some more complex shapes that are more time consuming that I'd rather avoid doing that..
回答1:
Found out can use:
CGAffineTransform transform = CGAffineTransformMakeScale(frame.size.width/shapeWidth, frame.size.height/shapeHeight);
CGMutablePathRef mutablePathTransform = CGPathCreateMutableCopyByTransformingPath(mutablePath, &transform);
来源:https://stackoverflow.com/questions/11471490/stretch-drawn-shape-to-fit-frame