Re: dragging to move objects around?
Re: dragging to move objects around?
- Subject: Re: dragging to move objects around?
- From: Greg Titus <email@hidden>
- Date: Wed, 22 Jul 2009 07:44:52 -0700
Hi Darren,
The point passed into -draggedImage:endedAt:operation: is in screen
coordinates, which is different from the window base coordinates that -
convertPointFromBase: expects. You want to convert from screen to
base, and then from base to your superview's coordinate system
(because the frame rect that you are setting is in terms of your
superview's coordinates):
aPoint = [[self window] convertScreenToBase:aPoint];
aPoint = [[self superview] convertPointFromBase:aPoint];
[self setFrameOrigin:aPoint];
I'll also mention that what you are doing here is not what is
generally intended by the dragged image protocol. It is usually used
for things like dragging icons or URLs to different apps/windows. If
you want to move something around within a single view you'd generally
detect what you clicked on in -mouseDown: and track the mouse in -
mouseDragged:. You can reset your view's frame on every mouseDragged:
call, so that the user will see the original view being moved around
on your view instead of an image "lifted" up from your window and
dragged anywhere on screen and then dropped.
Hope this helps,
- Greg
On Jul 22, 2009, at 4:27 AM, Darren Minifie wrote:
Hi
I am trying to implement the ability to move subviews around a view by
dragging them. The simple code I have thus far:
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint
operation:(NSDragOperation)operation{
[self setFrameOrigin:[self convertPointFromBase:aPoint]];
}
Here the image that is moving about is an exact copy of the original
subview. When the endedAt method executes, I would like the
subview's frame
to be changed to where the last position of the dragged image was.
The code
I have thus far is producing some undpredictable results. for
example, i'll
drag the subview straight down ( no change in x) but the subview
will be
moved somehwere far to the left or right.
--
Darren Minifie
Computer Science Masters Candidate
University of Victoria, BC. Canada
My Rants: www.noisyair.com
My Band: www.ohsnapmusic.com
_______________________________________________
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