Den 18:51 1. april 2012 skrev Per Bull Holmen <pbhol...@gmail.com> følgende: > 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:
OK, just because I am a naive altruist, I made one for you. This one takes a zoom factor where 1 is 1:1, 0.5 means half size, 2.0 means double size, etc. Works on my machine. I haven't checked what happens if the bounds origin gets negative coordinates. You may want to put in a little check to prevent that. -(void)zoom:(float)newFactor event:(NSEvent *)mouseEvent { NSScrollView *scrollView = [self enclosingScrollView]; NSClipView *clipView = [scrollView contentView]; NSRect clipViewBounds = [clipView bounds]; NSSize clipViewSize = [clipView frame].size; NSPoint clipLocalPoint = [clipView convertPoint:[mouseEvent locationInWindow] fromView:nil]; float xFraction = ( clipLocalPoint.x - clipViewBounds.origin.x ) / clipViewBounds.size.width; float yFraction = ( clipLocalPoint.y - clipViewBounds.origin.y ) / clipViewBounds.size.height; clipViewBounds.size.width = clipViewSize.width / newFactor; clipViewBounds.size.height = clipViewSize.height / newFactor; clipViewBounds.origin.x = clipLocalPoint.x - ( xFraction * clipViewBounds.size.width ); clipViewBounds.origin.y = clipLocalPoint.y - ( yFraction * clipViewBounds.size.height ); [clipView setBounds:clipViewBounds]; } 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