'SwiftUI TapGesture onStart / TouchDown
I am using the TapGesture in SwiftUI for MacOS. TapGesture is only recognized on TouchInsideOut
event, when releasing the press again. I want to call an action on touchdown and another on the end gesture.
There is a onEnded
state available for TapGesture but no onStart
.
MyView()
.onTapGesture {
//Action here only called after tap gesture is released
NSLog("Test")
}
Is there any chance to detect touch down and touch release?
I tried using LongPressGesture
aswell, but couldn't figure it out.
Solution 1:[1]
If by pure SwiftUI then only indirectly for now.
Here is an approach. Tested with Xcode 11.4.
Note: minimumDistance: 0.0
below is important !!
MyView()
.gesture(DragGesture(minimumDistance: 0.0, coordinateSpace: .global)
.onChanged { _ in
print(">> touch down") // additional conditions might be here
}
.onEnded { _ in
print("<< touch up")
}
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |