Created
April 22, 2020 03:41
-
-
Save SunXiaoShan/e509e54ee7db9a96f574437ae1765b95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func updateDataIndex(from fromIndexPath: IndexPath, to toIndexPath: IndexPath) { | |
let fromPosition = fromIndexPath.item | |
let toPosition = toIndexPath.item | |
let selected = cellDataList[fromPosition] as Int | |
DispatchQueue.main.async {[weak self] in | |
self?.cellDataList.remove(at: fromPosition) | |
var newindex = toPosition | |
if (newindex > self?.cellDataList.count ?? 0) { | |
newindex = self?.cellDataList.count ?? 0 | |
} | |
self?.cellDataList.insert(selected, at: newindex) | |
self?.collectionView.reloadData() | |
UIView.performWithoutAnimation { | |
self?.collectionView.reloadSections(IndexSet(integersIn: 0...0)) | |
} | |
} | |
} | |
func getCollectionViewColumnMaxCount() -> Int { | |
return ViewController.columnCount | |
} | |
func getCollectionViewRowMaxCount() -> Int { | |
return 10 | |
} | |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
let maxCount = getCollectionViewColumnMaxCount() * getCollectionViewRowMaxCount() | |
let bufferCount = maxCount - (self.cellDataList.count % maxCount) | |
return self.cellDataList.count + bufferCount | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment