WindowDragGesture
A gesture that recognizes the motion of and handles dragging a window.
Declaration
struct WindowDragGestureOverview
To recognize a window drag gesture on a view, create and configure the gesture, and then add it to the view using the gesture(_:isEnabled:) modifier. Consider also letting the gesture allowsWindowActivationEvents(_:) so that dragging the containing window works even when it’s inactive.
To add a window drag gesture to a Circle and change its color while a user performs the window drag gesture:
struct MyView: View {
@GestureState var isDraggingWindow = false
var dragWindow: some Gesture {
WindowDragGesture()
.updating($isDraggingWindow) { _, state, _ in
state = true
}
}
var body: some View {
Circle()
.fill(isDraggingWindow ? Color.green : .blue)
.frame(width: 50, height: 50)
.gesture(dragWindow)
.allowsWindowActivationEvents()
}
}