facetdigital / QuiltView

A UICollectionViewLayout subclass, used as the layout object of a UICollectionView for iOS and tvOS, developed in Swift, based on RFQuiltLayout.
Other
10 stars 2 forks source link

canMoveItemAt with QuiltView doesn't work as expected #3

Closed arronhunt closed 6 years ago

arronhunt commented 6 years ago

Demo: Giphy

As you can see, it isn't possible to rearrange cells easily. I am only allowed to drop a cell on its original location, or at the left-most column.

The code I'm using is here which is standard drag interaction for UICollectionViews

func configureLongPressGesture() {
        self.longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(self.handleLongGesture(gesture:)))
        self.quiltView?.addGestureRecognizer(longPressGesture)
    }
    @objc func handleLongGesture(gesture: UILongPressGestureRecognizer) {
        switch gesture.state {
        case .began:
            guard let selectedIndexPath = collectionView?.indexPathForItem(at: gesture.location(in: collectionView)) else {
                break
            }
            collectionView?.beginInteractiveMovementForItem(at: selectedIndexPath)
        case .changed:
            collectionView?.updateInteractiveMovementTargetPosition(gesture.location(in: gesture.view!))
        case .ended:
            collectionView?.endInteractiveMovement()
        default:
            collectionView?.cancelInteractiveMovement()
        }
    }
arronhunt commented 6 years ago

Do, it turns out that it's a problem with something I did, as creating a new project with a simpler implementation yields the correct results.

No idea what I'm doing wrong, but I can confirm this is not an issue with QuiltView itself.


Ninja Edit: The long press gesture was actually interfering with everything. Removing it entirely and using only collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool { return true } was all I needed.