Stretch Drawn Shape to fit Frame?

我的未来我决定 提交于 2019-12-24 14:28:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!