You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在MacBook全屏模式下利用刘海周围的显示区域?

实现Mac带刘海机型上App的「真正全屏」(覆盖刘海区域)

可行方案

方案一:全屏时完全隐藏菜单栏,窗口覆盖整个屏幕(包括刘海区域)

适用于AppKit原生项目:

func applicationDidFinishLaunching(_ aNotification: Notification) {
    guard let window = NSApplication.shared.mainWindow else { return }
    // 配置窗口样式,启用全尺寸内容视图并隐藏标题栏
    window.styleMask = [.borderless, .fullSizeContentView]
    window.titlebarAppearsTransparent = true
    window.titleVisibility = .hidden
    // 全屏时强制隐藏系统菜单栏
    NSApplication.shared.setPresentationOptions([.hideMenuBar])
    // 让窗口铺满整个屏幕(含刘海区域)
    window.setFrame(NSScreen.main!.frame, display: true)
}

注意:不要将Info.plist中的LSUIElement设为YES,否则App会完全后台运行且无法激活菜单栏。

方案二:全屏时菜单栏自动隐藏(鼠标移至顶部才显示),窗口平时覆盖刘海区域

同样适用于AppKit项目:

func applicationDidFinishLaunching(_ aNotification: Notification) {
    guard let window = NSApplication.shared.mainWindow else { return }
    // 保留窗口基础控制按钮(关闭/最小化/缩放),启用全尺寸内容视图
    window.styleMask = [.titled, .fullSizeContentView, .resizable, .closable, .miniaturizable]
    window.titlebarAppearsTransparent = true
    window.titleVisibility = .hidden
    // 设置菜单栏自动隐藏,仅鼠标移至顶部时显示
    NSApplication.shared.setPresentationOptions([.autoHideMenuBar])
    // 强制窗口铺满整个屏幕
    if let screenFrame = NSScreen.main?.frame {
        window.setFrame(screenFrame, display: true)
    }
}

SwiftUI项目适配

在App结构体中配置窗口属性:

@main
struct FullScreenDemoApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .frame(maxWidth: .infinity, maxHeight: .infinity)
                .ignoresSafeArea(.all) // 让内容突破安全区限制
        }
        .windowStyle(.hiddenTitleBar)
        .onAppear {
            guard let window = NSApplication.shared.mainWindow else { return }
            window.titlebarAppearsTransparent = true
            window.titleVisibility = .hidden
            // 选方案一:隐藏菜单栏
            NSApplication.shared.setPresentationOptions([.hideMenuBar])
            // 或方案二:自动隐藏菜单栏
            // NSApplication.shared.setPresentationOptions([.autoHideMenuBar])
            window.setFrame(NSScreen.main!.frame, display: true)
        }
    }
}

关键注意事项

  1. UISupportsTrueScreenSizeOnMac仅对Mac Catalyst项目生效,Mac原生App(AppKit/SwiftUI)无需设置。
  2. 若之前调整安全区无效,需确保视图添加了ignoresSafeArea(.all)(SwiftUI)或取消了内容视图的安全区约束(AppKit)。
  3. 单纯隐藏标题栏或移除自定义菜单无法实现覆盖刘海区域,必须配合fullSizeContentView和titlebarAppearsTransparent配置窗口样式,同时设置菜单栏的显示行为。

内容的提问来源于stack exchange,提问作者J. Doe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 07:55:40