在SwiftUI中,是否可以设置一个按钮,在点击时执行一个操作,在长按时执行另一个操作?
我尝试过以下代码:
我尝试过以下代码:
Button(action: {
self.handleButtonTap()
})
{
Text("My nice button")
.foregroundColor(.primary)
}
.onLongPressGesture {
print("Long pressed!")
}
或者使用以下方法替代:
.onLongPressGesture {
print("Long pressed!")
}
使用以下方法:
.gesture(longPress)
长按是指:
var longPress: some Gesture {
....
}
但是似乎什么都不起作用。 我最多能做的就是将长按手势附加到按钮的文本上,但即使在这种情况下,普通的轻触也无法使用。
如有好的建议,将不胜感激。