Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dok24

macrumors newbie
Original poster
Jun 30, 2011
11
0
Hey all,

I have a bit of a problem here. I am trying to draw shapes responding to touch events. My basic heirarchy is as follows:

Viewcontroller
-uiscrollview
-uiimageview(inside uiscrollview)

When somebody touches the uiimage view I want a shape to appear where they touched, and stay there even when the UISCrollview is panned, or zoomed away. Whenever I try to call drawRect in the uiimageview I get an invalid context error. Any suggestions?

Thanks in advance..
 
Whenever I try to call drawRect in the uiimageview I get an invalid context error. Any suggestions?

I suggest you supply your drawRect: code.

Likely you haven't got a line like this so that you can reference the context.
Code:
CGContextRef context = UIGraphicsGetCurrentContext();

Something to be concerned about is that you can't safely draw within a drawRect method of a UIView and expect to draw over the content that was there before entering the method. You have to act like the rectangle you are drawing into has been cleared. A UIImageView is a subclass of UIView so this should still apply. The way around that is to have the image in a separate UIImage variable and draw that to the rect before drawing your shape. If you want multiple shapes to build up over time, then things get more complicated.
 
I was able to remedy the problem by attaching a transparent UIView overtop of the UIImageView and drawing my shapes onto that.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.