How to lets users drag anywhere to move a window
2024년 6월 21일About 2 min
How to lets users drag anywhere to move a window 관련
SwiftUI by Example
Back to Home
How to lets users drag anywhere to move a window | SwiftUI by Example
How to lets users drag anywhere to move a window
Updated for Xcode 16
New in macOS 15
SwiftUI on macOS provides a special WindowDragGesture
type that is specifically designed to let users click and drag on a view to move your window. This is particularly helpful for windows that hide their title, which is more common in smaller utilities.
Use it like this:
VStack {
Text("You can drag from here")
Text("Or from here")
}
.gesture(WindowDragGesture())
To get the full effect, you should also add .windowStyle(.plain)
to your WindowGroup
or similar scene-level control.
Similar solutions…
How to open a new window | SwiftUI by Example
How to open a new window
Learn once, apply anywhere | SwiftUI by Example
Learn once, apply anywhere
How to support drag and drop in SwiftUI | SwiftUI by Example
How to support drag and drop in SwiftUI
How to let users move rows in a list | SwiftUI by Example
How to let users move rows in a list
How to make a scroll view move to a location using ScrollViewReader | SwiftUI by Example
How to make a scroll view move to a location using ScrollViewReader