Present attached sheet on MacOS SwiftUI

Viewed 242

I'd like to present a sheet descending from the toolbar's bottom edge in a SwiftUI MacOS app. How can I specify that attachment point?

The methods below present a sheet at the view's center.

I had thought attachment was implied in .beginSheet(). Answers I see discussing this use Storyboards, but I'd like to stick to code.

struct SomeView: View {

    func presentsSheetAtWindowCenter() {
        guard let mainWindow = NSApp.mainWindow else { return }
        let host = NSHostingController(rootView: someView)
        let sheetWindow = NSWindow(contentViewController: host)
        mainWindow.beginSheet(sheetWindow) { (response) in
            //
        }
    }
    
    func presentsSheetAtWindowCenterToo() {
        guard let mainCVC = NSApp.mainWindow?.contentViewController else { return }
        let host = NSHostingController(rootView: someView)
        mainCVC.presentAsSheet(host)
    }

}
0 Answers
Related