views:

27

answers:

1

Please can someone help with a simple transform I am attempting...

The code below zooms a thumbnail image into one that fills the screen. The problem is the thumbnail isn't centered (its offset towards the right), so the zoom actually needs to be moving the image towards the left, as it zooms in.

[fullsizeImageButton setTransform:CGAffineTransformMakeScale(.5,.5)];

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:0.9]; fullsizeImageButton.transform = CGAffineTransformMakeScale(1,1);

[UIView commitAnimations];

Thanks in advance for any help

A: 

You must build a bit more complex transform. Scale transform will scale the image relative to current origin (0,0), however, you want to scale relative to image's center. So, you must translate to the center, scale and translate back

Gobra
Thanks for your response. I've actually found another way to accomplish this:[fullsizeImageButton setTransform: CGAffineTransformConcat(CGAffineTransformMakeTranslation (-400,100),CGAffineTransformMakeScale(1,1))];I'm not sure if there is any performance issue with using the concat method compared to your suggestion.
Actually, it's similar to what I was talking about. But you apply scale with "fixing" translate afterwards while I have suggested more "classic" solution with moving the origin to the center of the image.Actually, you whatever you like :) Trick with origin is useful in most cases, for example, it's the only proper way to rotate an object around it's center.
Gobra