For my macOS app, I'm trying to change the mouse cursor to a pointing hand while hovering over a specific view. However, when the view is scaled with an animation triggered by hovering (using .scaleEffect()
and .animation()
), the cursor doesn't change as expected. Is there any workaround to fix this?
This is a sample code:
struct ContentView: View { @State private var hovering = false var body: some View { VStack { Text("Hover me") .padding() .background(hovering ? Color.blue : Color.gray) .scaleEffect(hovering ? 1.2 : 1.0) .animation(.linear(duration: 0.2), value: hovering) .onHover { hovering in self.hovering = hovering if hovering { NSCursor.pointingHand.push() } else { NSCursor.pop() } } } .frame(width: 200, height: 200) } }
This is how it works:
As you can see, when the pointer enters the view, the cursor changes momentarily before reverting back to the arrow icon.
I also tried using NSTrackingArea
with an NSView placed over the view, but it did not solve the issue. It might be that the combination of .scaleEffect()
and .animation()
is causing a forced cursor reset (possibly related to the use of NSWindow.disableCursorRects()
or something similar). However, I'm not entirely sure.
Any insights or suggestions would be greatly appreciated. Thanks!