a simple subclass of UIImageview, written in Swift to enable drag and drop with animation.
let's say you want to drag an apple(DKDraggableView) to cart(UIImageView), and perform some actions when you drop on cart.
you set the drop target with
apple.enableDragging = true
apple.setDropTarget(cart)
And get notified on drop by implement the method onDropedToTarget() of DKDraggableViewDelegate protocol
class DraggableViewController: UIViewController, DKDraggableViewDelegate {
@IBOutlet weak var apple:DKDraggableView!
@IBOutlet weak var cart: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
apple.delegate = self
apple.enableDragging = true
apple.setDropTarget(cart)
}
func onDropedToTarget(sender: DKDraggableView, target:UIView) {
NSLog("Drop to target \(target.tag)")
}
}
To run the example project, clone the repo, and run pod install
from the Example directory first.
iOS 8.0
Dkit_Dragdrop is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Dkit_Dragdrop"
daitran, [email protected]
Dkit_Dragdrop is available under the MIT license. See the LICENSE file for more info.