<!--
{
  "availability" : [
    "macCatalyst: -",
    "macOS: 10.0.0 - 10.7.0"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSView/dragImage:at:offset:event:pasteboard:source:slideBack:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSView(im)dragImage:at:offset:event:pasteboard:source:slideBack:"
  },
  "title" : "dragImage:at:offset:event:pasteboard:source:slideBack:"
}
-->

# dragImage:at:offset:event:pasteboard:source:slideBack:

Initiates a dragging operation from the view, allowing the user to drag arbitrary data with a specified icon into any application that has window or view objects that accept dragged data.

```
- (void) dragImage:(NSImage *) image at:(NSPoint) viewLocation offset:(NSSize) initialOffset event:(NSEvent *) event pasteboard:(NSPasteboard *) pboard source:(id) sourceObj slideBack:(BOOL) slideFlag;
```

## Parameters

`image`

The [`NSImage`](/documentation/AppKit/NSImage) object to be dragged.

`viewLocation`

The location of the image’s lower-left corner, in the view’s coordinate system. It determines the placement of the dragged image under the cursor. When determining the image location you should use the mouse down coordinate, provided in `theEvent`, rather than the current mouse location.

`initialOffset`

This parameter is ignored.

`event`

The left mouse-down event that triggered the dragging operation (see discussion below).

`pboard`

The pasteboard that holds the data to be transferred to the destination (see discussion below).

`sourceObj`

An object that serves as the controller of the dragging operation. It must conform to the [`NSDraggingSource`](/documentation/AppKit/NSDraggingSource) protocol and is typically the view itself or its [`NSWindow`](/documentation/AppKit/NSWindow) object.

`slideFlag`

A Boolean that determines whether the drag image should slide back if it’s rejected. The image slides back to `imageLoc` if `slideBack` is <doc://com.apple.documentation/documentation/Swift/true> and the image isn’t accepted by the dragging destination. If <doc://com.apple.documentation/documentation/Swift/false> the image doesn’t slide back.

## Discussion

This method must be invoked only within an implementation of the [`mouseDown(with:)`](/documentation/AppKit/NSResponder/mouseDown(with:)) or [`mouseDragged(with:)`](/documentation/AppKit/NSResponder/mouseDragged(with:)) methods.

Before invoking this method, you must place the data to be transferred on `pboard`. To do this, get the drag pasteboard object (`NSDragPboard`), declare the types of the data, and then put the data on the pasteboard. This code fragment initiates a dragging operation on an image itself (that is, the image is the data to be transferred):

```objc
- (void)mouseDown:(NSEvent *)theEvent
{
    NSSize dragOffset = NSMakeSize(0.0, 0.0);
    NSPasteboard *pboard;
 
    pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
    [pboard declareTypes:[NSArray arrayWithObject:NSTIFFPboardType]  owner:self];
    [pboard setData:[[self image] TIFFRepresentation] forType:NSTIFFPboardType];
 
    [self dragImage:[self image] at:[self imageLocation] offset:dragOffset
        event:theEvent pasteboard:pboard source:self slideBack:YES];
 
    return;
}
```

See the [`NSDraggingSource`](/documentation/AppKit/NSDraggingSource), [`NSDraggingInfo`](/documentation/AppKit/NSDraggingInfo), and [`NSDraggingDestination`](/documentation/AppKit/NSDraggingDestination) protocol specifications for more information on dragging operations.

## See Also

[`func shouldDelayWindowOrdering(for: NSEvent) -> Bool`](/documentation/AppKit/NSView/shouldDelayWindowOrdering(for:))

Allows the user to drag objects from the view without activating the app or moving the window of the view forward, possibly obscuring the destination.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)