iOS绘图命令Quartz 2D CGContext

时间:2012-10-15 16:30:22

标签: iphone objective-c ios quartz-2d cgcontext

您好我已经制作了一个自定义视图,它代表了一个带有轴等的图形,所以我在视图的drawRect:方法中使用Quartz 2D绘制了很多行。

但是我现在想改变它,所以我可以使用视图的控制器分别绘制图形的特定部分。例如,绘制x轴等待10秒,然后绘制y轴。所以我已经分离了绘图命令并将它们放在单独的方法中,因此可以从控制器调用它们,但是现在因为我在drawRect之外绘图:我无法获得图形上下文。

我该如何实施?石英2d甚至是正确的用途吗?

2 个答案:

答案 0 :(得分:1)

您可以将drawRect:功能分成多个UIView's,并让视图控制器管理在给定时间将绘制的视图

答案 1 :(得分:1)

为什么不从每个绘制操作创建UIImage并在UIImageView中绘制UIImage?

UIGraphicsBeginImageContext(self.view.frame.size);
//draw code here (draw previous UIIMage first before new drawing)
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

//now draw here

//get the UIImage
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

//set the UIImage to your UIImageView