最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Unable to resize sheet on macOS 15 with SwiftUI - Stack Overflow

programmeradmin2浏览0评论

In my macOS app, I can extend the main window of the app like that:

Window("SingleWindow", id: "single") {
   RootMacView()
     .frame(minWidth: 1000, maxWidth: .infinity, minHeight: 800, maxHeight: .infinity)
}

It works and I can use the arrows at the border of the window to extend it.

However, I didn't find the way to do the same thing with a sheet.

.sheet(isPresented: $showCellarsEditor) {
    VStack {
        Text("Test")
    }
    .frame(minWidth: 1000, maxWidth: .infinity, minHeight: 800, maxHeight: .infinity)    
}

The arrows never appear on the sides of the sheet.

What did I miss ? It's not possible to extend sheets on macOS ?

Thanks !

In my macOS app, I can extend the main window of the app like that:

Window("SingleWindow", id: "single") {
   RootMacView()
     .frame(minWidth: 1000, maxWidth: .infinity, minHeight: 800, maxHeight: .infinity)
}

It works and I can use the arrows at the border of the window to extend it.

However, I didn't find the way to do the same thing with a sheet.

.sheet(isPresented: $showCellarsEditor) {
    VStack {
        Text("Test")
    }
    .frame(minWidth: 1000, maxWidth: .infinity, minHeight: 800, maxHeight: .infinity)    
}

The arrows never appear on the sides of the sheet.

What did I miss ? It's not possible to extend sheets on macOS ?

Thanks !

Share Improve this question asked Mar 31 at 19:01 alex.bouralex.bour 2,9889 gold badges43 silver badges70 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Use the .fitted presentation sizing behaviour.

On macOS, presentations with .fitted sizing are user-resizable by default.

Also:

The presentation sizing is dictated by the ideal size of the content

So the initial size of the sheet will be the ideal size. You should pass in idealWidth: and idealHeight: too, otherwise the sheet will expand to the max size.

.sheet(isPresented: .constant(true)) {
    VStack {
        Text("Some Text")
    }
    .frame(minWidth: 400, idealWidth: 400, maxWidth: .infinity, minHeight: 400, idealHeight: 400, maxHeight: .infinity)
    .presentationSizing(.fitted)
}

On older versions, you can introspect the window for the sheet and add the .resizable style mask, but this will not respect the min/max sizes you set in SwiftUI.

.sheet(isPresented: .constant(true)) {
    VStack {
        Text("Some Text")
    }
    .frame(minWidth: 400, minHeight: 400)
    // suppose you want to support macOS 14
    .introspect(.window, on: .macOS(.v14)) { window in
        window.styleMask.formUnion(.resizable)
    }
}

Then you can use something like this to pick which version to run.

发布评论

评论列表(0)

  1. 暂无评论