i got the code but its not working, let me know if im did anything wrong. In the code i have a imageview which i created programmatically and adding the image into a uiview.Right now im unable to load the image in the "draggingView".
func longPressed(_ sender : UILongPressGestureRecognizer){
let locationInView = sender.location(in: self.view)
let cell = sender.view as? ParamterCollectionViewCell
var tImageView: UIImageView!
tImageView.frame = CGRect(x:0, y:0, width: 30 , height:30)
tImageView.image = parameterImageArray[0]
switch sender.state {
case .began:
// create an NSData object from myView
let archive = NSKeyedArchiver.archivedData(withRootObject: tImageView!)
// create a clone by unarchiving the NSData
draggingView = NSKeyedUnarchiver.unarchiveObject(with: archive) as? UIView
self.view.addSubview(draggingView!)
draggingView!.center = locationInView;
self.view.bringSubview(toFront: draggingView!)
break
case .changed:
if (contentView.frame.contains(locationInView)) {
draggingView?.center = locationInView;
}
break
case .ended:
break
default:
break
}
} }