• 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
"Google maps"-like zooming of NSScrollView's content view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: "Google maps"-like zooming of NSScrollView's content view
  • From: Nick <email@hidden>
  • Date: Sun, 01 Apr 2012 18:28:43 +0300

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

  • Follow-Ups:
    • Re: "Google maps"-like zooming of NSScrollView's content view
      • From: Per Bull Holmen <email@hidden>
    • Re: "Google maps"-like zooming of NSScrollView's content view
      • From: Dave Fernandes <email@hidden>
  • Prev by Date: Re: NSDocument disc undo stack
  • Next by Date: Re: "Google maps"-like zooming of NSScrollView's content view
  • Previous by thread: Re: NSDocument disc undo stack
  • Next by thread: Re: "Google maps"-like zooming of NSScrollView's content view
  • Index(es):
    • Date
    • Thread