是否可以将图像从collectionViewCell拖动到UIView中?
我正在创建一个游戏,用户可以在下一个VC中选择一些项目.我将每个项目表示为图像,用户可以通过将图像拖动到屏幕底部来选择每个项目.然后将图像重置为其原始位置.
如果我在我的代码中有UICollectionView函数,在UIViewCollectionView类中选择的图像都正确设置...我需要包括什么来将图像从上半部分(在CollectionView内)移动到下半部分(在UIView内) .
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let Cell:BackpackCollectionVC = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! BackpackCollectionVC
Cell.backpackImage.image = UIImage(named: self.resultString[indexPath.row]["imageName"]!)!
return Cell
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.items.count
}
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
Run Code Online (Sandbox Code Playgroud)
我可以使用下面的代码在UIView中移动图像.我无法弄清楚如何在UIViewCollectionView中实现它...
在ViewDidLoad中:
let imageGesture = UIPanGestureRecognizer(target: self, action: #selector(self.imageInUIViewDragged(gestureRecognizer:)))
uiviewImage.isUserInteractionEnabled = true
uiviewImage.addGestureRecognizer(imageGesture)
func imageInUIViewDragged(gestureRecognizer: UIPanGestureRecognizer) {
let translation = gestureRecognizer.translation(in: view)
let uiviewImage = gestureRecognizer.view!
//self.view.bounds.width - …Run Code Online (Sandbox Code Playgroud)