I’m new to Quartz2d so I hope this is an easy question to answer.
I have a scrollview whose content frame is 1024×768. Within this I push a custom view (with frame 1024×768) that uses Quartz2d to do some drawing. The idea is, I have a large area that the user can scroll around to see different parts.
The problem I’m having is, when I scroll on the device I get memory warning errors or terrible scrolling performance. This is no doubt because I am re-drawing the entire 1024×768 field. I thought that setting the clipping path to the UIScrollView offset would help.. and it does.. until i scroll.. in which case the view does not redraw until scrolling stops. telling the view to draw during scrollViewDidScroll also results in bad performance
can anyone tell me how i can optimize my drawing routine?
i have two images.. one of which is getting masked, and both being painted to the screen (one on top of the other)
- (void)drawRect:(CGRect)dirtyRect {
CGContextRef myContext = UIGraphicsGetCurrentContext();
// get our offset (where we've scrolled to)
CGPoint offset = scrollView.contentOffset;
// clip to our offset.. uncomment for good performance but terrible scrolling
//CGContextClipToRect(myContext, CGRectMake(offset.x, offset.y, 480, 320));
// make an image from the mask context
CGImageRef aMaskImage = CGBitmapContextCreateImage (myMaskContext);
// mask the first image
CGImageRef aImage = CGImageCreateWithMask(myImageRef1, aMaskImage);
CGContextDrawImage(myContext, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), myImageRef1);
CGContextDrawImage(myContext, CGRectMake(0, 0, self.frame.size.width, self.frame.size.height), aImage);
CGImageRelease(aImage);
CGImageRelease(aMaskImage);
}
thanks in advance for any help you can provide!
Generally to optimize scrolling big stuff you’d look into CATiledLayer.