Drag and Drop

Bring drag and drop to your app by using interaction APIs with your views.

Overview

With drag and drop in iOS, users can drag items from one onscreen location to another using continuous gestures. A drag-and-drop activity can take place in a single app, or it can start in one app and end in another.

Dragging multiple pictures from an app into Mail

The app from which an item is dragged is called the source app. The app on which an item is dropped is called the destination app. For drag and drop in a single app, that app plays both roles simultaneously. The complete user action from start to finish—using system-mediated gestures—is called a drag activity. A drag session, by contrast, is an object that’s managed by the system and that manages the items the user is dragging.

When dragging is in progress, the source and destination apps continue to run normally and support user interaction. A user can invoke the Dock, return to the Home screen, open a second app in Split View, and even start another drag activity.

Unlike in macOS, iOS drag and drop supports multiple simultaneous drag activities—as many as the user’s fingers can handle. You can design your app so that the user can sequentially add drag items to an in-progress drag session, and a destination app can accept multiple, simultaneous drops.

Text views and text fields automatically support drag and drop. Collection views and table views offer dedicated, view-specific methods and properties, and text views offer APIs for customizing the views’ drag-and-drop behavior. You can configure any custom view to support drag and drop, as well.

Topics

First Steps

Understanding a Drag Item as a Promise

Use drag items to convey data representation promises between a source app and a destination app.

Making a View into a Drag Source

Adopt drag interaction APIs to provide items for dragging.

Making a View into a Drop Destination

Adopt drop interaction APIs to selectively consume dragged content.

Adopting Drag and Drop in a Custom View

Demonstrates how to enable drag and drop for a UIImageView instance.

Adopting Drag and Drop in a Table View

Demonstrates how to enable and implement drag and drop for a table view.

Drag-and-Drop Interactions

Add interactions to your views to make them drag sources or drop destinations.

UIDragInteractionDelegate

The interface for configuring and controlling a drag interaction.

UIDropInteractionDelegate

The interface for configuring and controlling a drop interaction.

UIInteraction

The interface for attaching a gesture-based behavior to a view, such as to express a drag, drop, or spring-loaded interaction.

UIDragInteraction

An interaction to enable dragging of items from a view, employing a delegate to provide drag items and to respond to calls from the drag session.

UIDropInteraction

An interaction to enable dropping of items onto a view, employing a delegate to instantiate objects and respond to calls from the drop session.

Spring-Loaded Interactions

Enable spring loading to support drag and drop for your navigable UI.

UISpringLoadedInteractionBehavior

The interface for specifying the behavior of a spring-loaded interaction.

UISpringLoadedInteractionSupporting

The interface for automatically adding and removing the spring-loaded interaction for drag and drop, based on the value of the springLoaded property.

UISpringLoadedInteraction

An interaction object for configuring and controlling spring-loaded, user-driven navigation during a drag activity.

UISpringLoadedInteractionContext

The interface for configuring, and responding to, the context for a spring-loaded interaction.

UISpringLoadedInteractionEffect

The interface for providing visual styling to a spring-loaded interaction based on the interaction state.

Drag Sources

Specify drag items for drag and drop.

UIDragItem

A representation of an underlying data item being dragged from one location to another.

UIDragDropSession

The common interface for querying the state of both drag sessions and drop sessions.

UIDragSession

The interface for configuring a drag session.

UIDragAnimating

The interface for providing custom animation alongside the system's lift, drop, and cancellation animations.

Drop Destinations

Specify how a destination view consumes drag items.

UIDropSession

The interface for querying a drop session about its state and associated drag items.

UIDropProposal

A configuration for the behavior of a drop interaction, required if a view accepts drop activities.

UIDropOperation

Operation types that determine how a drag and drop activity resolves when the user drops a drag item.

UIDropSessionProgressIndicatorStyle

The drop-progress indicator styles for the drop session, used while data is moving from the source to the destination.

Item Providers

Work with data-representation promises for drag and drop.

NSItemProvider

An item provider for conveying data or a file between processes during drag and drop or copy/paste activities, or from a host app to an app extension.

NSItemProviderReading

The interface for supporting instantiation of objects using data loaded by an item provider, used by a destination app when consuming pasted or dropped items.

NSItemProviderWriting

The interface for supporting initialization of an item provider based on an object, used by a source app when providing copied or dragged items.

Pasteboard Support

Simplify the requesting and consuming of appropriate data representations for pasted and dropped items.

UIPasteConfiguration

A paste configuration for use by responder objects to declare their ability to accept specific data types for pasting and for drag-and-drop activities.

Custom Drag Item Previews

Apply customizations to make drag item previews more appealing and meaningful to the user.

UIDragPreviewParameters

A set of parameters for adjusting the appearance of a drag item preview.

UIDragPreview

A graphical preview for a single drag item, used by the system after a drag has started and when no related animation is running.

UIDragPreviewTarget

A geometric specification for the source or destination of a drag item preview, used by the system when a user drops items or cancels a drag activity.

UITargetedDragPreview

A drag item preview used by the system during lift, drop, or cancellation animation.

See Also

User Interface

Views and Controls

Present your content onscreen in specific ways and define the interactions allowed with that content.

View Management

Manage your interface using view controllers and facilitate navigation around different screens of content.

System View Controllers

Use the built-in UIKit view controllers to pick images, edit videos, share content, print files, and much more.

Accessibility

Make your app more accessible to users with disabilities.

Animation and Haptics

Provide feedback to users using view-based animations and haptics.

Windows and Screens

Provide a container for your view hierarchies and other content.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software