IKImageView: how to create an app looks like Preview

817 Views Asked by At

I'm working on an apllication that as a view with an IKImageView object inside. I can zoom image in the center position of the image, but I cannot zoom with the mouse position as "anchor point" of the image looks like Preview app.

I have the mouse position coordinates (relative to the image).

I can center the image in a specific point with this function:

- (void)centerSourceImageInPoint:(NSPoint)point
{
IKImageView *theImage = sourceImageController.imageView;

NSPoint pointInView = [theImage convertImagePointToViewPoint:point];

NSRect activeRect = [sourceImageView bounds];
NSPoint origin = CGPointMake(pointInView.x - activeRect.size.width / 2, pointInView.y - activeRect.size.height / 2);

[theImage setBoundsOrigin:origin];}

e.g. if mouse point is (3;3) the image will translate until image point (3;3) is in the center of view.

0

There are 0 best solutions below