'NSCursor issue with drag gesture
I need to use deferent cursor for a view, but it seems onHover modifier and gesture modifier got conflict with together. As you can test the code the cursor is not stable in drag process and it change shape for some reason! Is there any better approach for this?
struct ContentView: View {
@State private var offset: CGSize = .zero
var body: some View {
ZStack {
Color.yellow
.frame(width: 500, height: 500)
Circle()
.fill(Color.blue)
.frame(width: 50, height: 50)
.offset(offset)
.gesture(DragGesture(minimumDistance: 0, coordinateSpace: .local)
.onChanged { dragValue in
NSCursor.pointingHand.push()
offset = CGSize(width: dragValue.translation.width, height: dragValue.translation.height)
}
.onEnded { _ in offset = .zero; NSCursor.pointingHand.push() })
.onHover(perform: { isHovering in
if isHovering {
NSCursor.pointingHand.push()
}
else {
NSCursor.arrow.push()
}
})
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
