开发者

iPhone SDK: Image scaling problem

In my app I i开发者_运维百科ncrease 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜