tags:

views:

23

answers:

2

I've tried this demo code and gotten it to work fine:

http://www.techotopia.com/index.php/An_iPhone_Graphics_Drawing_Tutorial_using_Quartz_2D

What I'd like to do, however, is to do the same custom drawing onto a panel or canvas of some sort sitting on the view (instead of drawing on the view itself). I'd also like to have other controls (like buttons) on the same view, and have the button clicks control the actual drawing.

Is there an easy way to do this?

+1  A: 

You can probably just use a dedicated subview (use the view you have created) that you draw on manually and have its sibling views (buttons etc) sit on top of it. Just need a wrapper view to hold them all.

Ben
I tried putting another View onto my View in Interface Builder, and then setting that View as the referencing outlet, but that didn't work (it made the second view full-screen and didn't draw anything on it).
MusiGenesis
You'll need to make sure your view is a subview of that new view, and that the correct classes are assigned in ib.
Ben
+1  A: 

At least a couple options.

You can create a subview programmatically, sized to not cover the controls, put what to draw into some kind of model object that the subview can see from its drawRect, and call setNeedsDisplay on the subview from the view with the controls.

Or you can create a CGBitmap drawing context, draw into that bitmap context from the view with the controls, and then assign that bitmap context to the CALayer of a subview when you want to update.

hotpaw2