quartz2d translating the origin
Posted
by
qwertyp96
on Stack Overflow
See other posts from Stack Overflow
or by qwertyp96
Published on 2011-01-14T23:25:22Z
Indexed on
2011/01/15
0:53 UTC
Read the original article
Hit count: 208
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)
© Stack Overflow or respective owner