3

In my app I increase an images size, and decrease it, using the following code:

float xx = image.frame.origin.x;
float yy = image.frame.origin.y;

image.frame = CGRectMake(xx,yy, width*0.98, height*0.98);


float xx = image.frame.origin.x;
float yy = image.frame.origin.y;

image.frame = CGRectMake(xx,yy, width*1.02, height*1.02);

What this code does is it scales the image from an origin of the top left, therefore as the scale is done, the image focal point moves off the screen, increase by increase, decrease by decrease.

So the problem I have with this, is that the focal point of my image is not the top left, but in a specific point on the image. When my image is scaled it scales using the top left as its origin. How can I either change the point at which the image scales from, or preferably, mathematically calculate a translation of the new shape, so that the new focal points position would be moved to where the unscaled images focal point would have been? Thanks

Sam
  • 1,343
  • 5
  • 18
  • 30

1 Answers1

0

With your method of scaling you should recalculate the other point in the image that you want to be the origin point. And from that new point you should get the new xx and yy coordinates or you could use image.center.

You should also have a look at CGAffineTransform Reference because every UIView has a transform property.

Teodor Kostov
  • 313
  • 1
  • 11
  • I'm not sure what you mean, recalculate the other point? as far as my code goes it doesn't even include that point yet, I know its co-ordinates, do you mean that every time I scale the image that point would have to be recalculated? And how can I get the new xx and yy from a point somewhere in the image, what calculations? – Sam Jun 25 '11 at 13:26
  • By "the other point" I mean the point that you need - the focal point. You have an image which in your case is represented as an origin point width and height. If you know these 4 parameters and if you know the transformations that are applied you can calculate the position of every pixel in your image. So when you scale your image, in order to place it in the position that you want, you have to recalculate your desired position also. (Beacuse apparently the framework is using another position as an anchor point.) – Teodor Kostov Jul 28 '11 at 12:10