• 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
Re: dragging to move objects around?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >dragging to move objects around? (From: Darren Minifie <email@hidden>)

  • Prev by Date: When saving the managed object context
  • Next by Date: Re: When saving the managed object context
  • Previous by thread: dragging to move objects around?
  • Next by thread: RE: dragging to move objects around?
  • Index(es):
    • Date
    • Thread