RAReorderableLayout
RAReorderableLayout copied to clipboard
Drop cell to empty section not working
It is not possible to drop a cell to an empty section. How do I achieve that?
Hi, I have the same problem. So I find other flow layout in github, copy and modify the code. Now I resolved it. Maybe bad implementation but it works for me. I hope it can help you. https://github.com/rainbownight/RAReorderableLayout
fileprivate func getGhostIndexPath(_ cellCenter: CGPoint) -> IndexPath? {
guard let numberOfSections = self.collectionView?.numberOfSections,
let contentRect = self.collectionView?.contentSize else {
return nil
}
let columnWidth = contentRect.width / CGFloat(numberOfSections)
for section in 0 ..< numberOfSections {
let X: CGFloat = columnWidth * CGFloat(section)
let Y: CGFloat = 0.0
let W: CGFloat = columnWidth
let H: CGFloat = contentRect.height
let columnRect = CGRect(x: X, y: Y, width: W, height: H)
if columnRect.contains(cellCenter) {
guard let numberOfItems = self.collectionView?.numberOfItems(inSection: section) else {
return IndexPath(item: 0, section: section)
}
return IndexPath(item: numberOfItems, section: section)
}
}
return nil
}
p.s. I haven't tested it yet :) too eager to post my idea :D