Seem to be having a bit of an issue trying to draw my view into a context.
My basic setup is, I have a view controller that owns a UIPageViewController
You must not call [self.layer renderInContext:]
in drawRect:
, period. As you have figured out, renderInContext:
calls drawRect:
if it is implemented, which will cause an infinite recursion.
You should render a book as is separately, then use the rendered image to let users draw on top of it. One way to do that is to enclose a self-contained drawing code in the UIGraphicsBeginImageContext()
/UIGraphicsEndImageContext()
block and use the resulting image in drawRect:
. Another way is to use two different views which are not subviews of each other, one drawing an unaltered book, the other drawing user sketches.
EDIT: first of all, you need an original image (book page, whatever). Draw it inside a UIGraphicsBeginImageContext()
/UIGraphicsEndImageContext()
block without calling [self.layer renderInContext:]
and save it in the view's ivar (say, self.currentImage
). In touchesMoved:withEvent:
call setNeedsDisplay
(it will call drawRect:
for you) to update the view. Use self.currentImage
in drawRect:
as the background image.
I hope I'm not too vague.