0

我正在使用一个名为 Quarkee 的应用程序将徽标从 SVG 转换为 Quartz 2d 代码,这是一种享受。唯一的问题是我似乎无法弄清楚如何调整结果大小。如果我设置 UIView 的框架,drawRect 的结果会在框架中保持巨大。我如何让它成为我正在设置的框架的大小?

下面是一个输出的例子。

有人可以帮忙吗?

- (void)drawRect:(CGRect)rect
{

CGContextRef context = UIGraphicsGetCurrentContext();
CGColorSpaceRef colorspace_1 = CGColorSpaceCreateDeviceRGB();
CGFloat components_1[] = {0.9961,0.9961,0.9961, 1.0000};
CGColorRef color_1 = CGColorCreate(colorspace_1, components_1);
CGContextSetFillColorWithColor(context,color_1);

CGContextMoveToPoint(context, 0.4960,0.1090);
CGContextAddLineToPoint(context,662.9260,0.1090);
CGContextAddLineToPoint(context,662.9260,227.8780);
CGContextAddLineToPoint(context,0.4960,227.8780);
CGContextAddLineToPoint(context,0.4960,0.1090);
CGContextClosePath(context);


CGContextFillPath(context);
4

2 回答 2

1

这里的解决方案是使用 view.transform = CGAffineTransformMakeScale(0.5f, 0.5f); 调整视图大小

于 2012-06-30T17:04:16.440 回答
0

看看这些值:

CGContextMoveToPoint(context, 0.4960,0.1090);
CGContextAddLineToPoint(context,662.9260,0.1090);
CGContextAddLineToPoint(context,662.9260,227.8780);
CGContextAddLineToPoint(context,0.4960,227.8780);
CGContextAddLineToPoint(context,0.4960,0.1090);

调用该drawRect方法时,您可以使用self.bounds视图的当前矩形并根据它调整这些值。您说您已经从应用程序生成了此代码 - 这些应用程序通常在生成代码时硬编码您绘制的图形的大小,因此您必须查看这些值与您绘制的图像的实际大小之间的关系和根据self.bounds大小使它们动态...

于 2012-06-23T15:17:30.833 回答