Re: "Google maps"-like zooming of NSScrollView's content view
Re: "Google maps"-like zooming of NSScrollView's content view
- Subject: Re: "Google maps"-like zooming of NSScrollView's content view
- From: Dave Fernandes <email@hidden>
- Date: Sun, 01 Apr 2012 11:52:31 -0400
Just a comment about the UI… I find this behavior horribly counter-intuitive. I always end up zooming when I mean to pan.
On 2012-04-01, at 11:28 AM, Nick wrote:
> Hello
>
> I am trying to implement a zooming of a content view (actually it is a
> PDFView page) using a mouse scrolling wheel.
> What I want to have in the end - is to have the final content view
> zoomed in or out in a way that the point, where the mouse was located,
> does not move during this zooming operation (this point would be some
> kind of an anchor around which the rest of the content view should be
> zoomed). Here is an example of this: http://maps.google.com
>
> I've managed to make the view zoom in and out using a view's center
> point as such an anchor (this is an example i found on the internet):
>
> float zoomFactor = 1.3;
>
> -(void)zoomIn
> {
> NSRect visible = [scrollView documentVisibleRect];
> NSRect newrect = NSInsetRect(visible, NSWidth(visible)*(1 -
> 1/zoomFactor)/2.0, NSHeight(visible)*(1 - 1/zoomFactor)/2.0);
> NSRect frame = [scrollView.documentView frame];
>
> [scrollView.documentView
> scaleUnitSquareToSize:NSMakeSize(zoomFactor, zoomFactor)];
> [scrollView.documentView setFrame:NSMakeRect(0, 0,
> frame.size.width * zoomFactor, frame.size.height * zoomFactor)];
>
> [[scrollView documentView] scrollPoint:newrect.origin];
> }
>
> -(void)zoomOut
> {
> NSRect visible = [scrollView documentVisibleRect];
> NSRect newrect = NSOffsetRect(visible,
> -NSWidth(visible)*(zoomFactor - 1)/2.0, -NSHeight(visible)*(zoomFactor
> - 1)/2.0);
>
> NSRect frame = [scrollView.documentView frame];
>
> [scrollView.documentView
> scaleUnitSquareToSize:NSMakeSize(1/zoomFactor, 1/zoomFactor)];
> [scrollView.documentView setFrame:NSMakeRect(0, 0,
> frame.size.width / zoomFactor, frame.size.height / zoomFactor)];
>
> [[scrollView documentView] scrollPoint:newrect.origin];
> }
>
> 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
> _______________________________________________
>
> 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
_______________________________________________
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