• Stars
    star
    671
  • Rank 67,266 (Top 2 %)
  • Language
    Objective-C
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[iOS/deprecated!] Stop using context menus. Drag and drop instead, even between apps!

CoreDragon

DEPRECATED: Please use Apple's Drag'n'drop APIs introduced in iOS 11 instead.

cocoapods license
Twitter email

CoreDragon is a drag'n'drop library for iOS applications. Instead of using context menus, modal view controllers, share sheets and other "indirect manipulation" ways of moving data around, it's much more intuitive to just grab the thing you want to move, and drop it on the place where you want to move it to.

CoreDragon uses similar concepts as the drag'n' drop APIs on MacOS, and modifies them to work better in a world with view controllers. It works within a single application, and on modern iPads, between applications that are running in split screen mode.

CoreDragon was originally called SPDragNDrop, and was a Hackweek experiment written by me during the December 2012 Hackweek at Spotify. Since I really loved the idea and would hate for the code+idea to just rot away, Spotify allowed me to release the code under Apache 2.0 before my employment there ended.

See a demo introduction with two sample applications that show you the full feature set of CoreDragon over at https://www.youtube.com/watch?v=AQ7B2x-LHnQ.

Installation

  1. Add pod 'CoreDragon' to your Podfile
  2. Run pod install
  3. Add #import <CoreDragon/CoreDragon.h> from your bridging header, prefix header, or wherever you want to use drag'n'drop features

Getting Started

Installation

By default, CoreDragon uses a long-press-and-drag gesture to start and perform dragging. To install this default gesture, call enableLongPressDraggingInWindow: from your Application Delegate like so:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
	[[DragonController sharedController] enableLongPressDraggingInWindow:self.window];
    return YES;
}

Registering things that can be dragged

When you have a view that you would like to allow your users to drag, you can register it with -[DragonController registerDragSource:delegate:]. You would probably call it from a view controller's viewDidLoad, setting the view controller as the delegate. Whenever a dragging operation is initiated from this view, it is up to your view controller to provide the data for the object being dragged by putting it on a pasteboard:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [[DragonController sharedController] registerDragSource:label1 delegate:self];
}

- (void)beginDragOperation:(id<DragonInfo>)drag fromView:(UIView *)draggable
{
	// Required: Provide the data to be dragged by adding it to the dragging info's pasteboard:
	[drag.pasteboard setValue:text forPasteboardType:(NSString*)kUTTypePlainText];
	
	// By default, the item being dragged is represented by a screenshot of the draggable view.
	// Optionally, you can set 'title', 'subtitle' and 'draggingIcon' on the dragging info
	// to give it a pretty icon.
	NSString *text = [(UILabel*)draggable text];
    drag.title = text;
    drag.draggingIcon = [UIImage imageNamed:@"testimage"];
}

Drag sources are automatically unregistered when they are deinited.

Registering drop targets

Now that the user is holding an object with their finger, they will need somewhere to drop it. You can register drop targets in a very similar manner to drag sources. The delegate protocol for drop targets has several methods:

  • For accepting the dragged data (required)
  • For indicating that it does or does not support being dragged to
  • For springloading (hovering over the drop target to navigate into it, like hovering an icon in Finder while dragging)
  • For customizing the visualization of the drop target based on where the user's finger is pointing (to support custom highlighting in a table view, etc).

A simple drop target could look like so:

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [[DragonController sharedController] registerDropTarget:label2 delegate:self];
}

// Ensure that we only receive drops for plain text
- (BOOL)dropTarget:(UIView *)droppable canAcceptDrag:(id<DragonInfo>)drag
{
	return [drag.pasteboard containsPasteboardTypes:@[(NSString*)kUTTypePlainText]];
}

// When some plain text is dropped on this target, set the label's text to the incoming text.
- (void)dropTarget:(UIView *)droppable acceptDrag:(id<DragonInfo>)drag atPoint:(CGPoint)p
{
	[(UITextView*)droppable setText:[drag.pasteboard valueForPasteboardType:(NSString*)kUTTypePlainText]];
}

Examples

DragonFrame

A "photo frame" app with the simplest possible drag and drop support. Has a single image view which accepts drops on one tab, and another tab with a few example photos.

Features:

  • Registering drag sources (example photos)
  • Registering drop targets (the photo frame)
  • Two-handed navigation: Grab a photo with one hand, and tap the tab bar to navigate to the photo frame.

DragonPhotos

This is a photo organizer app with folder support, demoing all features of CoreDragon.

Photos are laid out in a collection view in a user-defined order. Dropping a photo onto another photo creates a folder. Photos can be imported from the camera roll, or dragged to the application.

Features:

  • Registering drag sources (photos and folders)
  • Registering drop targets (folders and the view controller's root view)
  • Multiple dragging representations.
    • Image data is put on pasteboard to support dragging images to other applications.
    • Database reference is put on pasteboard to support reordering and reorganizing photos within the application.
  • Custom highlighting. It is possible to re-order objects within a folder by drag-and-drop, with an indicator showing the new location for an item as a custom highlight view.
  • Spring-loading. By hovering an object over a folder, the hovered folder view controller is opened, so that you can continue organizing within it.
  • Two-handed navigation. Instead of spring-loading, you can grab an object with one hand, and then tap in the application with your other hand to navigate to the location in the application where you want to drop the object.

dragonphotos

DragonChat

TO BE IMPLEMENTED

A fake chat app with demo conversations, where you can attach photos to the conversation by dragging them from DragonPhotos. The purpose of this app is to show a real-world use case of drag&drop.

License

Apache 2.0

Background

I've always loved multitouch. In addition, I love working spatially with windows and drag&drop. Neither concept has gained much traction on iPad, and not even exploring those concepts means missing out.

At Spotify, I got my windows by copying Loren Brichter's stacked panes navigation. Finally, I had tactile, direct manipulation navigation. However, all contextual operations were still performed in modes. If you wanted to share a track with a friend, you'd go into the context menu mode for your track by long-pressing it, then the sharing mode by choosing an option in a table, then the friend selection mode... To me, it would be so much more natural to just grab the track, and drag it onto the icon representing my friend. Suddenly you'd be able to remove all these modes, and have direct manipulation of your objects.

I met my hero Bret Victor at WWDC 2012, and we talked for a while about drag & drop on iPad, and he added a very important point I hadn't thought about for many years: with multitouch, you can pick something up with one hand, and navigate with the other. This concept had already blown my mind once back in 2005, when TactaPad released a few amazing concept movies and then never showed themselves again.

So during Hackweek December 2012, I mocked up drag&drop inside the Spotify iPad app. It worked really well. You could pick up a track with your right hand, tap the tab bar with your left hand, navigate around the UI a bit either by tapping on items with your left hand or springloading with your right, and dropping your item when you were done.

Unfortunately, the idea never got any traction within the company and the branch died. That was over a year ago, and the code is now uncompileable. (Yes, when your build system breaks with every point update of Xcode, code really does rot.) Thus, the only screenshot I have is of the trivial demo app in this repo. Hopefully it is inspiring enough that you now feel the immediate need to use the code or the concept in your own app! Hooray!

After WWDC 2015, when split-screen multitasking was introduced, I started working on inter-app drag'n'drop. Here's what it looked like on 20150831, and further progress on 20151129.

Inter-app drag'n'drop was released beginning of 2016, with a demo movie on YouTube (moved over from lookback).

More Repositories

1

cfxr

[cocoa] Mac port of sfxr with document support, etc
Objective-C
351
star
2

SPMediaKeyTap

[Cocoa] SPMediaKeyTap is a global event tap for the play/pause, prev and next keys on the keyboard.
Objective-C
268
star
3

SPAsync

[ObjC] Tools for abstracting asynchrony in Objective-C.
Objective-C
131
star
4

spot

[iPhone] DO NOT USE FOR INSPIRATION. Look at CocoaLibSpotify! Open source Spotify client.The project is very very dead.
C
89
star
5

NuRemoting

Remote control your iOS app using Nu (lisp-on-objc)
Objective-C
79
star
6

MeshPipe

IPC library for iOS
Objective-C
47
star
7

URLSessionTest

NSURLSession background upload sample code
Objective-C
46
star
8

Orbivoid

iOS SpriteKit game used in my YouTube tutorial.
Objective-C
37
star
9

SPSuccinct

[Cocoa] Low verbosity Cocoa and KVO
Objective-C
32
star
10

OverPing

[Swift] Pings google every 1s and displays the current network latency in a bar graph
Swift
27
star
11

TCTypeSafety

[ObjC] hack to get type safe collections in ObjC
Objective-C
26
star
12

Cerfing

[ObjC] Lightweight network protocol
Objective-C
17
star
13

OverTask

[Cocoa] Hierarchical, visual, fullscreen todo app for absent-minded programmers
Objective-C
13
star
14

RemoteParameter

[Cocoa] Control any KVO-compliant value in your iPhone app from a GUI app on your mac.
Objective-C
13
star
15

TCFileViewer

[iOS] File system viewer for debugging purposes
Objective-C
13
star
16

game-music-emu

My fork of Blargg's Game Music Emu, adding cocoa wrappers.
11
star
17

StervoxyTanks

[iPhone] Multiplayer tanks
Objective-C
10
star
18

pwcblocks

[Documentation] Programming with C Blocks (On Apple Devices)
10
star
19

deathtroid

Super Metroid clone, adding online multiplayer deathmatch. Python.
Python
10
star
20

C3LineGraph

[iPhone] Simple animating graph class
Objective-C
10
star
21

FakeAccelerometer

[iPhone+Mac] Using your Mac's accelerometer to control the iPhone Simulator
Objective-C
7
star
22

delegationhelper

[Cocoa] You'll never need to write [delegate respondsToSelector:] again.
7
star
23

OverKeyboard

[Mac+iOS] virtual network keyboard NOT based on VNC!
Objective-C
7
star
24

orbavoidance

A Cocoa 10.6 clone of Kalinium's flash game of the same name
Objective-C
6
star
25

mutroid

Super metroid music game. Download: http://cl.ly/0d1q0i1m0k0h
C
6
star
26

WindowStackOrganizer

Objective-C
6
star
27

NSObject-AddMethod

+(BOOL)addMethodForSelector:(SEL)selector typed:(const char*)types implementation:(id)blockPtr;
Objective-C
5
star
28

CoCA

Cocoa Core Audio wrapper.
Objective-C
5
star
29

GMESPlugin

Spotify plugin: play NES, GYM and other console music in Spotify
C++
5
star
30

atime

[Cocoa] You remember Swatch Internet Time? No? Phew!
Objective-C
5
star
31

ppticker

[Cocoa] Ett app för att följa hur många medlemmar Piratpartiet har JUST NU!
Objective-C
4
star
32

padlua

[CocoaTouch] Interactive Lua interpreter for iPad
C
4
star
33

BitCraft

[CocoaTouch] Maybe some day an RTS.
Objective-C
4
star
34

mari0

NOT MINE!! Just git-ified the source so I can start hacking on it.
Lua
4
star
35

SerialFHTPlotter

[Mac Swift] Plots incoming FFT data from serial port (from arduino or similar)
Swift
4
star
36

overload

[iphone] Abstract turn-based strategy game
Objective-C
3
star
37

aurality

24h game competition entry
3
star
38

cominecraft

minecraft client in cocoa? wtf?
Objective-C
3
star
39

tcinteractiveassert

[Cocoa] Like NSAssert, but shows an alert dialog allowing you to ignore the error once, for the rest of the session, or to abort.
3
star
40

nevyn-bin

just my ~/bin folder of my standard scripts I can't live without
Shell
3
star
41

Aurality2

Objective-C
3
star
42

CubeWalker

experimenting with SceneKit
Objective-C
3
star
43

CPUMonster

[iOS] Waste CPU cycles like there is no tomorrow.
Objective-C
3
star
44

cavesave

[Cocoa] Transfers Cave Story/Doukutsu Monogatari save files between Mac OS and Windows
Objective-C
2
star
45

spotcache

[C++] A cache class on top of sqlite
C++
2
star
46

ch100-metal-primer

CocoaHeads Stockholm #100: Metal for the Masses
Rich Text Format
2
star
47

NevHaptics

[ObjC] Experimental framework for haptic and pressure sensitive UI on iOS
Objective-C
2
star
48

LBMediaToolkit

Presentation about AVFoundation and other Apple media frameworks
Objective-C
2
star
49

TCCircleMenu

Objective-C
2
star
50

myass

[iPhone SDK app: Solves quadratic equations] My lil' brother needed some math help, so we wrote an iPhone project together to do it for him!
Objective-C
2
star
51

bitshift

A .mod and console music player for iPhone
2
star
52

ocsh

bash is for wussies
Ruby
2
star
53

Overlay

Objective-C
2
star
54

SKAdventure

Apple's "Adventure" sample code, unchanged, so it's easy to fork. NOT WRITTEN BY ME!
Objective-C
2
star
55

Selectweet

2
star
56

Fonster

Fontastic! Windowed web browser for iPad. (WTF‽)
Objective-C
2
star
57

TransmissionRemote

iPhone app with "magnet:" link support
Objective-C
2
star
58

Quest

A 2D adventure game engine
Objective-C
2
star
59

OverView

Objective-C
2
star
60

Hej

Objective-C
2
star
61

GameControllerDemo

[iOS] GameController.framework demo, presented at Cocoaheads Stockholm, October 1st 2014
Objective-C
2
star
62

OverAnimate

[Arduino] Library for animating stuff
C++
1
star
63

MandyEarring

Bluetooth controllable ear ring (using TinyDuino with a BT4 shield and a motor on pin 5)
C++
1
star
64

Mobot

[Cocoa] For learning to 'read' Kansas City Standard
Objective-C
1
star
65

DropHole

[Mac/iOS] Drag-and-drop files to devices auto-discovered on the network. AirDrop but works?
Objective-C
1
star
66

LivSpel

a game for my niece
Swift
1
star
67

OcuCam

[iOS] Halloween oculus+ipad hack. Cylon eye + sounds + camera playthrough hdmi
Objective-C
1
star
68

Tanks3

Let's clone Wii Play Tanks! again.
Objective-C
1
star
69

CimmerianPurple

[Swift] GlobalGameJam2015 entry. FPS for blind people. Uses PureData to generate in-game sound.
Swift
1
star
70

inverse-cybernetics

Instead of teaching a computer how to talk to a human... teach a human how to talk to a computer through direct computer-to-human connections.
Arduino
1
star
71

OvermindMonitor

just a tool for work
Objective-C
1
star
72

Occluded

C#
1
star
73

touchid

You can either bitch or moan about missing functionality, or you can implement it yourself.
Objective-C
1
star
74

Window-Stack-Organizer

1
star
75

nevclock

just playing around with an arduino, making an alarm clock
C
1
star
76

Concertion

[iOS] Hackaway project
Objective-C
1
star