我有一个 iPad 应用程序,很容易移植到 Mac。
我正在使用触摸开始/移动/结束,它的端口很好,但我想在 Mac 上的 iOS 应用上使用右键单击。
如何在 UIKit for Mac App 中注册右键?
最佳答案
我不认为你可以添加任意的右键单击手势,但如果你想要的只是右键单击以显示上下文菜单,那么新的 UIContextMenuInteraction
已满足您的需求:
let interaction = UIContextMenuInteraction(delegate: self)
someView.addInteraction(interaction)
… 然后实现 UIContextMenuInteractionDelegate
方法来配置和显示上下文菜单。在 macOS 上,“上下文菜单交互”是右键单击,上下文菜单将显示为标准的 macOS 弹出菜单。
UIContextMenuInteraction
目前的文档非常少,因此如果您需要,这篇博文会很有帮助:
https://kylebashour.com/posts/ios-13-context-menus
关于ios - 右键单击 UIKit for Mac,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56683098/