0

我的 ViewController 为我创建 contextMenu 的所有 UICollectionView 提供了三个 UICollectionView,但是对于最后一个 UICollectionView,我不想显示菜单,对于 <return UIContextMenuConfiguration(identifier: nil, previewProvider: nil)> 一切都很好,但对于这个长按的 UICollectionview 动画没有禁用。

如何禁用最后一个 UICollectionView 的长按动画?这确实很容易,但我无法删除默认情况。

我的代码示例:

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)
        }
    }
4

1 回答 1

0

通过return nil安装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
    }
}
于 2021-02-24T12:34:01.960 回答