I have a UIImageView.
I would like to get it's context so that I can draw ontop of it.
I understand I can get my main graphic context by calling UIGraphicsGetCurrentContext()
, but I would like to draw on my image view, not the background of the form. Is this possible, and if so how?
I attempted 开发者_开发百科to draw to the main UI graphics context, but nothing appeared. I assume it is drawing under my image views. Am I correct or am I confused in this context?
You're a little confused. :) The view doesn't have a context. When the view is about to be painted on the screen, UIKit sets up a graphics context, gives it to the view, and calls the view's drawRect:
. The view can then put drawing instructions into the context. Once the view is done, UIKit whisks the context away and turns the drawing instructions into a bitmap, which it puts on the screen.
So the view only has access to a graphics context that's going to the screen when UIKit sets it up. In order for you to get access to this context, you have to put code inside the view's drawRect:
. You can't actually draw into an arbitrary view on the screen.
What you can do is put your own, mostly-transparent view on top of it and draw into that.
精彩评论