2
votes

Hi I've made a custom view which represents a graph with axises etc so I'm drawing lots of lines using Quartz 2D in the view's drawRect: method.

However I'd like to change this now so I can use my view's controller to draw specific parts of the graph separately. Eg draw the x-axis wait 10 seconds then draw the y-axis. So I've separated the drawing commands and placed them into separate methods so they can be called from the controller but now since I'm drawing outside drawRect: I can't get a graphics context.

How should I go about implementing this? is quartz 2d even the right thing to use?

2

2 Answers

1
votes

You could separate the drawRect: functionality into multiple UIView's, and have the view controller manage which views will draw at a given time

1
votes

Why don't you create an UIImage from each draw operation and draw the UIImage in an UIImageView ?

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