是否可以在UIKitForMac中轻松启用右键单击Catalyst应用程序?
目前,以下代码在单击鼠标左键时运行良好,但在单击鼠标右键时没有任何调用:
button.addTarget(self, action: #selector(doSomething), for: .touchUpInside)//用于左击而不是右击
@objc func doSomething(sender:UIButton, event:UIEvent) -> Bool {发布于 2020-08-24 19:50:44
https://developer.apple.com/design/human-interface-guidelines/ios/controls/context-menus/
右键单击Mac Catalyst即可使用此菜单
1.添加交互
let interaction = UIContextMenuInteraction(delegate: self)
yourButton.addInteraction(interaction)2.添加扩展UIContextMenuIteractionDelegate
extension AccountViewVC: UIContextMenuInteractionDelegate {
public func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { suggestedActions in
let delete = UIAction(title: "Delete", image: UIImage(systemName: "arrow")) { action in
}
let children = [delete]
return UIMenu(title: "Main Menu", children: children)
})
}}https://stackoverflow.com/questions/63531513
复制相似问题