|
1 | | -# DragAndDropCrossApp |
| 1 | +# SplitViewDragAndDrop |
2 | 2 | Easily add drag and drop to pass data between your apps |
| 3 | + |
| 4 | +[](https://developer.apple.com/iphone/index.action) |
| 6 | +[](https://developer.apple.com/swift/) |
| 7 | + |
| 8 | +<img src="demo.gif" height="500"/> |
| 9 | + |
| 10 | +# Setup |
| 11 | +- Copy the "SplitViewDragAndDrop" folder into your project |
| 12 | +- Make sure to call |
| 13 | +```SplitViewDragAndDrop.configure(groupIdentifier: <YOUR-APP-GROUP-ID>)``` in ```application:didFinishLaunchingWithOptions:```. **Your apps must share that app group in order to communicate**. |
| 14 | +- Configure the view you want to drag with ```SplitViewDragAndDrop.handleDrag(viewToDrag: <THE-DRAGGABLE-VIEW>, identifier: <AN-IDENTIFIER>, dataToTransfer: <SOME-DATA-TO-TRANSFER>)``` |
| 15 | + where |
| 16 | + - **viewToDrag** is a UIView and it will be snapshotted and dragged around |
| 17 | + - **identifier** is a string rappresenting an unique identifier. |
| 18 | + - **dataToTransfer** is a Data, it could be an image, a pdf ecc.. |
| 19 | + - Configure the drop observer with |
| 20 | + ``` |
| 21 | + SplitViewDragAndDrop.addDropObserver( |
| 22 | + targetView: <A-TARGET-VIEW>, |
| 23 | + identifier: <AN-IDENTIFIER>, |
| 24 | + draggingBegan: { frame, draggedViewSnapshotImage, dataTransfered in |
| 25 | + // the drag is began, here you can perform some ui changes in order to tell the user where to drag the item |
| 26 | + }, |
| 27 | + draggingValidation: { frame, draggedViewSnapshotImage, dataTransfered in |
| 28 | + return <A-BOOL> |
| 29 | + }, |
| 30 | + completion: { frame, draggedViewSnapshotImage, dataTransfered, isValid in |
| 31 | + // the drag is complete and you can use dataTrasfered if you want |
| 32 | + } |
| 33 | + ) |
| 34 | + ``` |
| 35 | + where |
| 36 | + - **targetView** is a UIView and it will be the center of the dragged item when the user end the dragging and the validation succedded |
| 37 | + - **identifier** is a string rappresenting an unique identifier |
| 38 | + - **draggingBegan** is a closure that will be called when the drag is began |
| 39 | + - **draggingValidation** is a closure that will be called when the drag is ended. You have to return a value that indicate if the drag is valid or not. If that value is true, the dragged view will be moved to the center of the **targetView**, otherwise it will be moved back to it's original position. |
| 40 | + - **completion** is a closure that will be called after the validation. |
| 41 | + |
| 42 | +# Demo |
| 43 | +In this repository you can also find a demo. |
| 44 | + |
| 45 | +# Info |
| 46 | +If you like this git you can follow me here or on twitter :) [@MarioIannotta](http://www.twitter.com/marioiannotta) |
| 47 | + |
| 48 | +Cheers from Italy! |
0 commit comments