I'm trying to write a finger paint type program using Quartz graphics. The problem I'm having is when the screen rotates. The dots and lines I draw "creep" away from where I'm touching. With each successive touch, the previous dot creeps away. This does not happen in either of the two portrait modes, but it does in both landscape modes.
I may be mistaken but I think my problem is with this call:
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width , self.view.frame.size.height)];
drawImage
is a UIImageView
in my main view controller's nib file.
I've also tried using the following:
[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height )];
[drawImage.image drawInRect:drawImage.bounds];
[drawImage.image drawInRect:self.view.bounds];
I guess I really have no idea whether to use self
or my UIImageView
object for this call.
I have tried both, in both the drawInRect
call and where I set up my drawing context (being consistent).
I set up the context like this in viewDidLoad
(to try to make a persistant context that I don't have to reset things in each time I draw - using push and pop context).
//---------------- set up a persistent context for drawing -----------------
UIGraphicsBeginImageContext(self.view.frame.size);
context = UIGraphicsGetCurrentContext();
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, curWidth);
CGContextSetRGBStrokeColor(context, curRed, curGreen, curBlue, curAlpha);
UIGraphicsPushContext(context);
I tried to get rid of the context I set up on rotation and reinitialize it when the view rotated, thinking this was the problem, but I'm not sure I did it right.