在 iPhone 7 iOS 15 中运行时,上下文菜单配置在 UICollection 视图中不起作用

问题描述 投票:0回答:1

我正在尝试将上下文菜单选项添加到 iOS 应用程序中的 UICollection 视图。这是我的代码。此代码适用于最新的 iPhone,如 iPhone 12、13、14。但当我在 iPhone 7 上测试它时,无论是物理设备还是运行 iOS 15 的模拟器都不起作用。 iPhone 7 中不显示上下文菜单。由于 iPhone 7 支持 3D 触摸,我是否需要专门为 iPhone 7 实现 Peek 和 Pop?

func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemsAt indexPaths: [IndexPath], point: CGPoint) -> UIContextMenuConfiguration? {
    let configuration = UIContextMenuConfiguration(identifier: nil,previewProvider: nil){ _ in
        let delete = UIAction(title:"Delete",image: nil){ _ in
            print("Delete")
     
        }
        return UIMenu(title: "",options: .displayInline,children: [delete])
    }
    return configuration
 
}
ios swift iphone uicollectionview
1个回答
0
投票

也许您可以使用 contextMenuConfigurationForItemAt 而不是 contextMenuConfigurationForItemsAt 来做到这一点?

func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
    let configuration = UIContextMenuConfiguration(identifier: nil,previewProvider: nil){ _ in
        let delete = UIAction(title:"Delete",image: nil){ _ in
            print("Delete")
     
        }
        return UIMenu(title: "",options: .displayInline,children: [delete])
    }
    return configuration
 
}
© www.soinside.com 2019 - 2024. All rights reserved.