Interface Builder Style Drag & Drop

Discussion in 'Mac Programming' started by Spike099, Aug 5, 2009.

  1. Spike099 macrumors regular

    Joined:
    Feb 18, 2007
    Location:
    Canada
    #1
    Alright! I've got to ask it now! Err.

    I've been trying to implement in house drag and drop so I can mimic some behavior found in IB (resizing, snapping etc).

    This is how i've done it so far.

    When a user clicks on an image in the main window, another window appears ( the drag window ). An image is drawn in the window to mimic the image in the main window.

    When the user now drags the drag window "should" now be key and receive mouse events. But it isn't. I have to click again to so it can receive mouseDragged events.

    The window appears as it should using [window makeKeyAndOrderFront]; but because it wasn't the window receiving the mouseDown event, it isn't receiving mouseDragged. I've tried [window sendEvent:prevMouseDownEvent].

    Is this possible? "while a mouse event is directed at whatever window lies under the pointer" - Apple Docs
    So... It should work in theory according to the docs.
     
  2. Spike099 thread starter macrumors regular

    Joined:
    Feb 18, 2007
    Location:
    Canada
    #2
    Okay, I got it working...

    Not entirely the way I wanted, but it works...

    The image that responds to the mouseDown:event and pulls up the window also responds to mouseDragged/mouseUp and passes the events to the other window...
     
  3. jnozzi macrumors newbie

    Joined:
    Nov 29, 2010
    #3
    JLNDragEffectManager

    I wrote a Cocoa class called JLNDragEffectManager that handles morphing between two images during drag just like dragging from Interface Builder's library palette into a window. It's BSD licensed.

    I wrote an article to explain its design and use here. I also wrote an article showing how I use it in one of my own products here.
     

Share This Page