quartz2d translating the origin
- by qwertyp96
My understanding of quartz2d is that the code CGContextTranslateCTM(context, x, y); translates the coordinate system. I have a quartz2d view with lots of shapes on it, and the user needs to be able to pan around and zoom it. However, when using the CGContextScaleCTM(context, scaleX, scaleY); code, everything scales around the origin, not the center of the viewpoint the user is viewing.
My solution to this was to use the following code:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 512.0+offset.x, 384.0+offset.y);
//(512, 384) is the center of the iPad screen
CGContextScaleCTM(context, scale, scale);
You can translate around fine, but things still scale into the corner. What's wrong?
EDIT: Oh. Wow. Duh. If you move the origin, the shapes move too, so you can't move it relative to the shapes. Now I know what's wrong, but how do I do that?(move the origin independently of the shapes)