1

My ViewController have the three UICollectionView for all the UICollectionView I did create contextMenu, but for the last UICollectionView I am don't want to show the menu and for <return UIContextMenuConfiguration(identifier: nil, previewProvider: nil)> all work well but for this UICollectionview animation of long-press didn't disabled.

How to disable the animation of the long press for the last UICollectionView? It does be easy but I can't delete the default case.

Example of my code:

func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
        
        switch collectionView {
        case favoriteCollectionView:
             return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) {...}
        case allCollectionView:
             return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) {...}
        default:
              // This menu empty and doesn't show but the animation of long pressed not disabled how to fix this?
             return UIContextMenuConfiguration(identifier: nil, previewProvider: nil)
        }
    }
Ice
  • 680
  • 1
  • 10
  • 23

1 Answers1

1

Pass return nil insted of return UIContextMenuConfiguration(identifier: nil, previewProvider: nil)

func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {

    switch collectionView {
    case favoriteCollectionView:
        return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) {...}
    case allCollectionView:
        return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) {...}
    default:
        return nil //<-- HERE
    }
}
Raja Kishan
  • 16,767
  • 2
  • 26
  • 52
  • 1
    Thank you this is works well :). I did try the same in the past and in my case, it didn't work, but now it is work, it looks like I made a mistake somewhere ). – Ice Feb 24 '21 at 12:48