-
Install with CocoaPods
pod "UIView+DragDrop"
-
Include UIView+DragDrop.h
#import "UIView+DragDrop.h"
-
Call 'makeDraggable' or 'makeDraggableWithDropViews:delegate:' on a UIView or UIView subclass, set a delegate, and configure as needed
//make a view draggable [self.view1 makeDraggable]; [self.view1 setDelegate:self]; // Set drop views with an array of UIView elements [self.view1 setDropViews:@[..]]; // Restricts drag motion to x axis [self.view1 setDragMode:UIViewDragDropModeRestrictX];
##Documentation
###Making a UIView Draggable
- (void) makeDraggable;
- (void) makeDraggableWithDropViews:(NSArray *)views delegate:(id<UIViewDragDropDelegate>)delegate;
###Configure
- (void) setDelegate:(id<UIViewDragDropDelegate>)delegate;
- (void) setDragMode:(UIViewDragDropMode)mode;
- (void) setDropViews:(NSArray*)views;
###Drag Modes
typedef NS_ENUM( NSInteger, UIViewDragDropMode) {
UIViewDragDropModeNormal, // Drag in any direction (default)
UIViewDragDropModeRestrictY, // Restrict to x axis
UIViewDragDropModeRestrictX // Restrict to y axis
};
@protocol UIViewDragDropDelegate <NSObject>
@optional
- (void) view:(UIView *)view wasDroppedOnDropView:(UIView *)drop;
- (BOOL) viewShouldReturnToStartingPosition:(UIView*)view;
- (void) draggingDidBeginForView:(UIView*)view;
- (void) draggingDidEndWithoutDropForView:(UIView*)view;
- (void) view:(UIView *)view didHoverOverDropView:(UIView *)dropView;
- (void) view:(UIView *)view didUnhoverOverDropView:(UIView *)dropView;
@end
To run the example project; clone the repo, and run pod install
from the Example directory first.
Ryan Meisters, ryanmeisters@gmail.com
- Ryan Meisters @ryanmeisters
UIView+DragDrop is available under the MIT license. See the LICENSE file for more info.