Den 17:28 1. april 2012 skrev Nick <eveningn...@gmail.com> følgende:

> However, I can't figure out how to make zooming like google maps does,
> preserving that mouse "anchor" point's location. Could you give me a
> hint?
>
> Thank you

I can't give you readymade example code, but here's the steps:

1) Find the mouse location in the clip view's ( = content view's )
coordinate space. ( [clipView convertPoint:[theEvent locationInWindow]
formView:nil] )
2) Compute the mouse location in fractions of the clip view's bounds.
All the way to the left means x = 0, all the way to the right means x
= 1. Vice versa with y. If the point is equal to the content view's
origin, the fraction point becomes { 0, 0 }, if it's in the center,
you get { 0.5, 0.5 }, if the point's x value equals the
bounds.origin.x + bounds.size.width, and vice versa with y, you get {
1, 1 }.
3) Manipulate the bounds of the content view (NOT the document view),
so that the bounds rectangle gets smaller if you zoom in, larger if
you zoom out. How much you change the content view bound's location is
given by the fraction you found in point 2 (along each axis). How much
you change the bound's size is given by one minus the fraction you
found in point 2. For the fraction point { 0, 0 }, you do not touch
the bound's origin at all. For the fraction point { 1, 1 } you only
change the origin, not the size.

Don't touch the document view's frame or bounds. This way of zooming,
by manipulating the content view's bounds instead of the document
view's frame has worked fine for me in the past. It's usually easier,
I think.

Per

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to