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: Graham Cox <email@hidden>
- Date: Thu, 13 Oct 2011 09:48:55 +1100
HI James,
I would say that even if you have got it working, you're going out on a limb there.
If you have elements in your interface that are positioned statically rather than part of the general content of the 'canvas' they might be better off being put into a separate view that is independent of DrawKit. Without knowing what these elements are however, it's hard to advise.
--Graham
On 13/10/2011, at 6:24 AM, 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
_______________________________________________
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