ios - 右键单击 UIKit for Mac

标签 ios uikitformac

我有一个 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/

相关文章:

ios - self.property = objective-c 中的 self.property

ios - iOS 应用程序可以共享数据吗?

ios - 核心数据和 NSFRC 显示条目但不会在每次启动和键值编码错误中持续存在

ios - "UserNotificationsUI"在构建 UIKit for Mac 错误时不可用

swift - 检测 UIKIt for Mac 的应用程序最小化事件?

swift - 如何在 Catalyst 应用程序中将搜索栏添加到 NSToolbar 中?

ios - iOS 8.1.3 中设备方向返回错误

ios - 克隆 UIImage iOS 部分时的内存问题

ios - 检测 UIKit for Mac (Catalyst) 中的单个修饰符键更改