RAReorderableLayout icon indicating copy to clipboard operation
RAReorderableLayout copied to clipboard

Drop cell to empty section not working

Open mschonvogel opened this issue 9 years ago • 2 comments

It is not possible to drop a cell to an empty section. How do I achieve that?

mschonvogel avatar May 11 '15 15:05 mschonvogel

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

HoneyLuka avatar Nov 14 '15 08:11 HoneyLuka

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

awedeebawe avatar May 07 '17 16:05 awedeebawe