Re: Locking an object's location to the scroll view (not the document)
Re: Locking an object's location to the scroll view (not the document)
- Subject: Re: Locking an object's location to the scroll view (not the document)
- From: James Maxwell <email@hidden>
- Date: Wed, 12 Oct 2011 15:22:00 -0700
Holy smokes!
Okay, just used the wrong Rect. Needed to use documentVisibleRect instead of the contentView's bounds. Ugh... Working fine now.
J.
On 2011-10-12, at 12:24 PM, James Maxwell wrote:
> 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
------------------------------------------------------
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