ios - UIContextMenuActionProvider 将不需要的复选标记图标放在项目上
问题描述
问题
我正在实施UIContextMenuInteraction
,并以我无法解释或找到修复的行为结束。从屏幕截图中可以看出菜单项带有复选标记的问题。这不是有意的,这些复选标记会自动添加。理想情况下,我想使用SF Symbols
,但我添加的任何图像最终都会成为这个复选标记。即使我将图像设置为零,它仍然会添加这个奇怪的复选标记。
采取的其他步骤:重新安装 SF Symbols 和 SF Pro,清理构建,重新启动 xCode / Simulator
转载:模拟器iOS 13.3,iPhone 7 iOS 13.3
系统: Catalina 10.15.1,xCode 11.3.1
代码:
import UIKit
class ViewController: UIViewController {
let sampleView = UIView(frame: CGRect(x: 50, y: 300, width: 300, height: 200))
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(sampleView)
sampleView.backgroundColor = .systemIndigo
let interaction = UIContextMenuInteraction(delegate: self)
sampleView.addInteraction(interaction)
}
}
extension ViewController: UIContextMenuInteractionDelegate {
func contextMenuInteraction(
_ interaction: UIContextMenuInteraction,
configurationForMenuAtLocation location: CGPoint
) -> UIContextMenuConfiguration? {
let actionProvider: UIContextMenuActionProvider = { [weak self] _ in
let like = UIAction(
title: "Like",
image: UIImage(systemName: "heart"),
identifier: nil,
discoverabilityTitle: nil,
attributes: [],
state: .on
) { _ in
}
let copy = UIAction(
title: "Copy",
image: nil,
identifier: nil,
discoverabilityTitle: nil,
attributes: [],
state: .on
) { _ in
}
let delete = UIAction(
title: "Delete",
image: UIImage(systemName: "trash"),
identifier: nil,
discoverabilityTitle: nil,
attributes: [.destructive],
state: .on
) { _ in
}
return UIMenu(
title: "",
image: nil,
identifier: nil,
options: [],
children: [
like, copy, delete
]
)
}
let config = UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: actionProvider)
return config
}
}
解决方案
您需要UIAction.state
从.on
to更改.off
为摆脱复选标记。
推荐阅读
- python - 在列表列表中查找不完全匹配
- python - Python Pandas 遍历整个列并检查它是否包含某个 str
- postgresql - Postgresql - 函数获取行作为参数 - 如何访问该行的列?
- python - 此处的 if-else 范围语句是否需要 int(n)?
- rest - 为远程系统上的 REST API 使用自签名证书
- ionic-framework - 在设备上安装了另一个离子应用程序时无法安装离子应用程序?
- php - 如何在php中使用array_in与多维数组
- sql - 计算整个赛道最快的5000米时间
- dialogflow-es - Google Action 在帐户关联之前要求提供参数
- regex - RegEx 用于捕获星号之间的内容,单词除外