• 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
Locking an object's location to the scroll view (not the document)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Locking an object's location to the scroll view (not the document)


  • Subject: Locking an object's location to the scroll view (not the document)
  • From: James Maxwell <email@hidden>
  • Date: Wed, 12 Oct 2011 12:24:35 -0700

I'm using GCDrawKit, which has been an amazing help in getting my app's interface together. However, I've run into a problem that's making me slightly crazy...

My main view is a zooming scroll view. Thanks to drawKit, I generally have no problems at all; it handles the zooming beautifully, so I don't even think about it. However, what I need to do now is to have certain objects remain in a fixed position, relative to the viewable area -- so if, for example, an object is in the upper-left corner, it will remain there during scrolling and zooming (I DO want it to zoom, but it should stay in the upper-left corner). I managed to get this working (or I thought I did), by telling my enclosingScrollView to post frame changed notifications, then using those to update the position of the object.

- (void)                updateWithScroll
{
    NSPoint selfOrigin = [self location];
    DKDrawingView* view = [(DKDrawingDocument*)[[self drawing] owner] mainView];
    NSRect bounds = [[[view enclosingScrollView] contentView] bounds];
    NSPoint origin = bounds.origin;
    if(self.lockXPositionToContentRect)
    {
        selfOrigin.x = origin.x + scrollOffset.x;
    }
    if(self.lockYPositionToContentRect)
    {
        selfOrigin.y = origin.y + scrollOffset.y;
    }
    [self setLocation:selfOrigin];
}

But unfortunately I forgot about zooming, so my objects only stay in their correct positions if I'm either: A) at a zoom scale of 1.0, or B) the scroll view is at the document's origin (i.e., 0,0 for both document and view). How do I do this for both scrolling and zooming?
(I tried multiplying the location coordinates by the scaling amount, but that doesn't quite do it -- it's closer, but not correct.)

Any help appreciated.

J.

------------------------------------------------------
James B. Maxwell
Composer/Researcher/PhD Candidate
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

  • Follow-Ups:
    • Re: Locking an object's location to the scroll view (not the document)
      • From: Graham Cox <email@hidden>
    • Re: Locking an object's location to the scroll view (not the document)
      • From: James Maxwell <email@hidden>
  • Prev by Date: Re: urlFromString creating bad URLs with string containing []
  • Next by Date: Can we talk iOS5 yet?
  • Previous by thread: Re: AVFoundation and kYUVSPixelFormat from AVPlayer
  • Next by thread: Re: Locking an object's location to the scroll view (not the document)
  • Index(es):
    • Date
    • Thread