gpt4 book ai didi

ios - UIContextMenu Action Provider 在项目上放置不需要的复选标记图标

转载 作者:行者123 更新时间:2023-12-04 02:39:19 25 4
gpt4 key购买 nike

问题

我正在实现 UIContextMenuInteraction,但最终出现了我无法解释或找不到修复的行为。从屏幕截图中看到的问题是菜单项有复选标记。这不是故意的,那些复选标记是自动添加的。理想情况下,我想使用 SF Symbols,但我添加的任何图像最终都会成为这个复选标记。即使我将图像设置为 nil,它仍然会添加这个奇怪的复选标记。

采取的其他步骤:重新安装 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

}

}

Weird checkmarks

最佳答案

您需要将 UIAction.state.on 更改为 .off 以去除复选标记。

关于ios - UIContextMenu Action Provider 在项目上放置不需要的复选标记图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60093347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com