拉伸形状适合框架? [英] Stretch Drawn Shape to fit Frame?
问题描述
我有一个应用程序,我绘制一个特殊的椭圆形,我通过一系列的Bezier路径,如下:
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);
我想知道,在核心图形中有没有什么办法可以采取我刚刚创建的形状,拉伸它水平和垂直,使其完全适合其视图框架? IE所以我不必手动进入我所有的点和值和写入它们的视图边界?我知道这种形状不会那么困难,但我有一些更复杂的形状,更加耗时,我宁愿避免这样做。
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..
推荐答案
找到可以使用:
CGAffineTransform transform = CGAffineTransformMakeScale(frame.size.width/shapeWidth, frame.size.height/shapeHeight);
CGMutablePathRef mutablePathTransform = CGPathCreateMutableCopyByTransformingPath(mutablePath, &transform);
这篇关于拉伸形状适合框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!