如何在 SwiftUI 中实现 Haptic/3D Touch?



如何在 SwiftUI 中检测触摸手势的力量?

我已经可以执行以下操作:

view.onTapGesture { ... }

但是,如何根据触摸力触发不同的闭包,或包装 UIKit 视图来实现此目的?

可以使用.contextMenu显示特定元素的操作列表。

Text("Press hard or hold for context menu")
.contextMenu
{
Button(action: { print("Action 1 triggered") }, label:
{
Text("Action 1")
})

Button(action: { print("action 2 triggered") }, label:
{
Text("Action 2")
})
}

最新更新