drawing on top of UIImageView

Discussion in 'iOS Programming' started by dok24, Jun 30, 2011.

  1. dok24 macrumors newbie

    Jun 30, 2011
    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:

    -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..
  2. xStep macrumors 68000

    Jan 28, 2003
    Less lost in L.A.
    I suggest you supply your drawRect: code.

    Likely you haven't got a line like this so that you can reference the context.
    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.
  3. dok24 thread starter macrumors newbie

    Jun 30, 2011
    I was able to remedy the problem by attaching a transparent UIView overtop of the UIImageView and drawing my shapes onto that.

Share This Page