• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "Google maps"-like zooming of NSScrollView's content view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Google maps"-like zooming of NSScrollView's content view


  • Subject: Re: "Google maps"-like zooming of NSScrollView's content view
  • From: Per Bull Holmen <email@hidden>
  • Date: Sun, 01 Apr 2012 19:56:36 +0200

Den 18:51 1. april 2012 skrev Per Bull Holmen <email@hidden> følgende:
> Den 17:28 1. april 2012 skrev Nick <email@hidden> 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 (email@hidden)

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:

This email sent to email@hidden


References: 
 >"Google maps"-like zooming of NSScrollView's content view (From: Nick <email@hidden>)
 >Re: "Google maps"-like zooming of NSScrollView's content view (From: Per Bull Holmen <email@hidden>)

  • Prev by Date: Re: Order of Finder labels
  • Next by Date: Re: "Google maps"-like zooming of NSScrollView's content view
  • Previous by thread: Re: "Google maps"-like zooming of NSScrollView's content view
  • Next by thread: Re: crash on OS X when popover closes
  • Index(es):
    • Date
    • Thread