개발/swift

Swift drag, drop and reorder collectionView Cell

lemonade 2020. 12. 4. 10:00
반응형

How to drag and drop collectionView Cell?

 

 

You can use dragDelegate and dropDelegate!

 

First, set delegate!

 

 

Second, implement drag method!

 

 

 

Note that replace item with your own cell item!

 

Now you can drag your cell!

 

Finally, implement drop method!

 

DropSessionDidUpdate method returns a UICollectionViewDropProposal. This is how we tell the DropDelegate that something is happening when the user drags a cell and drops it at a new location.

 

In performDropWith method, you should reorder your data list too.

 

Now you can reorder cell by drag, drop action!!

 

Happy Codding :)

반응형
그리드형

'개발 > swift' 카테고리의 다른 글

Swift How to init keychain when app deleted?  (0) 2020.12.12
Swift How to ignore return value?  (0) 2020.12.08
Swift try catch error handling  (0) 2020.12.01
Swift new feature in ios14, IDFA  (0) 2020.11.26
Swift How to detect screenshot action?  (0) 2020.11.22