• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Objective-C
  • Created almost 13 years ago
  • Updated over 12 years ago

Reviews

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

Repository Details

Versatile, easily configurable drag and drop classes for iPhone and iPad.

// draggable

Screenshot

wtf is this

It's currently not possible to use Cocoa's drag-and-drop classes and protocols in iPhone/iPad apps. This really sucks. Implementing a UIPanGestureRecognizer is really fucking boring.

SEDraggable is a subclass of UIView that fills this void, making it easy to add drag-and-drop functionality to any UIView in your application.

how

Note: check out the example project. It's a pain to explain code in English, and I didn't try very hard.

Add the source files to your Xcode project. Import the SEDraggable.h and SEDraggableLocation.h headers.

#import "SEDraggable.h"
#import "SEDraggableLocation.h"

To initialize an instance of SEDraggable, you'll probably want to use one of these:

- (id) initWithFrame:(CGRect)frame;
- (id) initWithImage:(UIImage *)image andSize:(CGSize)size;
- (id) initWithImageView:(UIImageView *)imageView;
// set up the UIImageView that will be used as the visible component of our draggable element
UIImage *image = [[UIImage alloc] initWithContentsOfFile:@"someFile.png"];
UIImageView *imageView = [UIImageView alloc] initWithImage:image];

// initialize the draggable element itself
SEDraggable *draggableView = [SEDraggable initWithImageView:imageView];

Of course, as mentioned, there are simpler init methods to suit different needs.

CGRect frame = CGRectMake(10, 10, 100, 100);
SEDraggable *draggableView = [SEDraggable initWithFrame:frame];
// ... or ...
SEDraggable *draggableView = [SEDraggable init];

using SEDraggableLocation's automatic behaviors

SEDraggableLocation allows you to easily switch between certain automatic behaviors -- for example, visually arranging a set of SEDraggable objects so that they don't appear to be haphazardly strewn about, or yanking an SEDraggable back to its original location when a drag-and-drop operation is unsuccessful for some reason.

Try something like the following. Run the code and then play around with the draggable objects to see how they behave.

SEDraggable *draggableView = ...

// create the SEDraggableLocation to represent the draggable element's starting point
CGRect homeLocationBounds = CGRectMake(10, 10, 100, 100);
CGRect otherLocationBounds = CGRectMake(200, 200, 100, 100);
SEDraggableLocation *homeLocation = [SEDraggableLocation initWithBounds:homeLocationBounds];
SEDraggableLocation *otherLocation = [SEDraggableLocation initWithBounds:otherLocationBounds];

// configure a whole litany of options
otherLocation.objectWidth = draggableView.frame.size.width;
otherLocation.objectHeight = draggableView.frame.size.height;
otherLocation.marginLeft = 3;
otherLocation.marginRight = 3;
otherLocation.marginTop = 3;
otherLocation.marginBottom = 3;
otherLocation.marginBetweenX = 3;
otherLocation.marginBetweenY = 3;
otherLocation.shouldAcceptDroppedObjects = YES;
otherLocation.shouldAutomaticallyRecalculateObjectPositions = YES;
otherLocation.shouldAnimateObjectAdjustments = YES;
otherLocation.animationDuration = 0.5f;
otherLocation.animationDelay = 0.0f;
otherLocation.animationOptions = UIViewAnimationOptionBeginFromCurrentState;
otherLocation.fillHorizontallyFirst = YES; // NO makes it fill rows first
otherLocation.allowRows = YES;
otherLocation.allowColumns = YES;

// add the draggable object, or maybe even several
draggableView.homeLocation = homeLocation;
[draggableView addAllowedDropLocation:homeLocation];
[draggableView addAllowedDropLocation:otherLocation];
[homeLocation addDraggableObject:draggableView];

SEDraggableLocation bounds

You can even specify different boundaries for where an SEDraggableLocation will accept dropped objects and where it will place them. And these two regions don't even have to be contiguous in any way! It's kind of cool to watch what happens if they're not -- when you drop your draggable objects, they fly from one area of the screen to another automatically.

These are the two properties you'll want to look at if you want to configure this kind of behavior:

@property (nonatomic, readwrite) CGRect responsiveBounds;
@property (nonatomic, readwrite) CGRect objectGutterBounds;

delegate messages

You can specify a delegate that will be notified of pertinent drag-and-drop events. Delegates of SEDraggable and SEDraggableLocation objects must conform either to the SEDraggableEventResponder protocol or the SEDraggableLocationEventResponder protocol, respectively. The two protocols define the following messages, all of which are optional:

@protocol SEDraggableEventResponder

- (void) draggableObjectDidMove:(SEDraggable *)object;
- (void) draggableObjectDidStopMoving:(SEDraggable *)object;

- (void) draggableObject:(SEDraggable *)object didMoveWithinLocation:(SEDraggableLocation *)location;
- (void) draggableObject:(SEDraggable *)object didStopMovingWithinLocation:(SEDraggableLocation *)location;

- (void) draggableObjectWillSnapBackToHomeFrame:(SEDraggable *)object;
- (void) draggableObjectDidEndSnappingBackToHomeFrame:(SEDraggable *)object;

- (void) draggableObject:(SEDraggable *)object didBeginSnapAnimationWithID:(NSString *)animationID andContext:(void *)context;
- (void) draggableObject:(SEDraggable *)object didEndSnapAnimationWithID:(NSString *)animationID andContext:(void *)context;

@protocol SEDraggableLocationEventResponder

- (void) draggableLocation:(SEDraggableLocation *)location didAcceptDroppedObject:(SEDraggable *)object;
- (void) draggableLocation:(SEDraggableLocation *)location didRefuseDroppedObject:(SEDraggable *)object;
- (void) draggableObject:(SEDraggable *)object wasRemovedFromLocation:(SEDraggableLocation *)location;

authors and contributors

bryn austin bellomy <[email protected]>

license (MIT license)

Copyright (c) 2012 bryn austin bellomy // robot bubble bath LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

FlatUIColors

Flat UI color palette helpers written in Swift.
Swift
171
star
2

solidity-auction

A simple auction dApp for Ethereum, written in Solidity.
JavaScript
130
star
3

Regex

Regex class for Swift. Wraps NSRegularExpression.
Swift
67
star
4

SwiftDataStructures

Basic data structures (OrderedDictionary, Stack, Queue, LinkedList, List) that supplement the Swift stdlib.
Swift
42
star
5

SwiftBitmask

NS_OPTIONS for Swift (type-checked bitmask container). Basically an easier-to-implement RawOptionSet.
Swift
36
star
6

dash-docset-generator

Node.js command line tool that generates Dash docsets from HTML, JSON, YAML, etc.
HTML
35
star
7

ObjC-DesignByContract

A small library of design-by-contract macros for Objective-C, based on code by Nicolas Roard.
Objective-C
23
star
8

SEBeamMeUpScotty

Reactive, super-simple iOS video upload classes for YouTube, Facebook, etc.
Objective-C
22
star
9

iOS-GTLYouTube

Google's Objective-C wrapper for the YouTube API, served up as a CocoaPod. No installation.
Objective-C
18
star
10

BrynKit

Making Obj-C/iOS development a little less excruciating.
Objective-C
16
star
11

GCDThreadsafe

Easy threadsafeing + the performance of Grand Central Dispatch.
Objective-C
15
star
12

iOS-CrackRock

Reactive in-app purchase helpers for brewing that delicious iOS fool-aid
Objective-C
14
star
13

otis

Documentation generator for Javascript, CoffeeScript, C, C++, Objective-C, Ruby, Python, AS3, Java, and everything else ever.
JavaScript
13
star
14

Funky

Functional programming tools and experiments in Swift.
Swift
13
star
15

ObjC-StatelyNotificationRobot

NSNotification wrapper that keeps track of state and notifies new observers of state immediately.
Objective-C
10
star
16

consensys-academy-prediction-market

A prediction market smart contract (Solidity) with a React frontend.
JavaScript
9
star
17

xcode-aqueducts

Xcode port of Aqueducts theme (from Sublime Text 2).
9
star
18

hook.io-zordon

hook.io WAN auto-discovery and connect hook
JavaScript
6
star
19

node-better-buffer

Buffer subclass with some smack-your-head-obvious methods (push, pop, growToAccommodate, clone, dataLength, etc.)
JavaScript
6
star
20

UpdateTimer

Scene update loop timer for SpriteKit, et al. (in Swift)
Swift
5
star
21

hook.io-hookify

Converts regular node.js modules into fault-tolerant, cloud-ready hook.io hooks in 20 lines of code or less.
JavaScript
5
star
22

go-structomancer

Golang struct reflection package
Go
4
star
23

bookmark-manager

JavaScript
2
star
24

DisasterCoin

Hackathon project
JavaScript
2
star
25

SEThuggedOutImageView

A better UIImageView with better animation control, easier gesture handling, and lots of guns.
Objective-C
2
star
26

ReactiveBoxer

Easiest layouts ever via ReactiveCocoa + MGBox2
Objective-C
2
star
27

SESimpleObjectArchiver

Simple classes for [un]serializing objects via NSCoding and saving/loading them to and from disk.
Objective-C
2
star
28

Sublime-Aqueducts

Aqueducts β€” theme for SublimeText 2 + 3.
Swift
2
star
29

EOS-boilerplate

A simple EOS smart contract boilerplate project with a Dockerized dev environment
Python
2
star
30

Entish

Game entity / component system (in Swift).
Swift
2
star
31

switchboard.js

Multi-events for the browser and node.js (i.e., handlers won't trigger until several specified events occur).
JavaScript
2
star
32

iOS-frameworkized-static-libs

Libraries (mainly other people's) that have been converted into .framework files that successfully compile against iOS.
Objective-C
2
star
33

ObjC-DesignByContract-experimental-2.0

Apparently contract programming keeps you from fucking up. Talentless iOS developers, it's your time to shine.
Objective-C
2
star
34

nappy

View formatted node.js api documentation in the cli / terminal
JavaScript
2
star
35

.vim

My .vim
Vim Script
1
star
36

gl4-game

An entity/component game engine in OpenGL 4 and Go.
Go
1
star
37

vim-command-regex

CoffeeScript
1
star
38

hook.io-markdown

1
star
39

hook.io-ranger

Helper hook for hook.io-zordon
JavaScript
1
star
40

SwiftTilemap

SpriteKit tilemap framework that parses TMX files (in Swift).
Swift
1
star
41

d.ts

TypeScript definition files I'm working on.
TypeScript
1
star
42

hook.io-cloudapp

JavaScript
1
star
43

go-rx

A set of basic, common Go concurrency patterns, very loosely adapted to the Rx model
Go
1
star
44

consensys-academy-splitter-remittance

ConsenSys Academy: Splitter + Remittance projects
JavaScript
1
star
45

hook.io-tropo

Hook.io hook for communicating with Tropo (a really rad, really affordable SMS / VoIP gateway)
CoffeeScript
1
star
46

weathernaut

CLI tool for querying the Weather Underground API
CoffeeScript
1
star
47

hook.io-github

Emit info about Github repositories on your hook.io hook cloud!
JavaScript
1
star
48

tsrun

Run Typescript (*.ts) files from the shell without having to pre-compile to Javascript. Useful for quickly writing command-line tools.
JavaScript
1
star