【问题标题】:SwiftUI: Using enterFullScreenMode on MacOSSwiftUI:在 MacOS 上使用 enterFullScreenMode
【发布时间】:2022-01-27 18:21:22
【问题描述】:

我一直在使用window.toggleFullScreen() 来呈现全屏窗口,但我发现这在用作单独显示器的 iPad 上不起作用。应用程序不会在此屏幕上转换 - 只会在调试窗口中发出哔声,而不会出现任何错误(希望对第一个问题有任何见解:)

此转换的代码 sn-p:

  window.collectionBehavior = [] 
  window.toggleFullScreen(self)
  • 框架调整大小由代表处理

我现在正在尝试使用window.contentView?.enterFullScreenMode。

这个转换没问题(即使在 iPad 上)但我缺少菜单和停靠栏

代码如下:

// AppDelegate
var window: NSWindow!

// applicationDidFinishLaunching()
window = NSWindow(contentRect: device.size, styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView], backing: .buffered, defer: false)
self.window.delegate = self
let contentView = ContentViewv11().frame(minWidth: 100, maxWidth: .infinity, minHeight: 50, maxHeight: .infinity)
window.contentView = NSHostingView(rootView: contentView.environmentObject(display).  ....etc

// initiated via menu item action:
let presOptions: NSApplication.PresentationOptions = [.autoHideMenuBar, .autoHideDock]
let optionsDictionary = [NSView.FullScreenModeOptionKey.fullScreenModeApplicationPresentationOptions: presOptions]
window.contentView?.enterFullScreenMode(NSScreen.main!, withOptions: optionsDictionary)
window.contentView?.wantsLayer = true \\tried also with this line removed

我还没有看到contentViewenterFullScreenMode 方法一起使用的示例。除了应用程序本身之外,这给了我一个完全空白的窗口。没有隐藏的停靠栏或菜单栏。该应用程序的用户至少需要菜单栏。帮助表示赞赏。

【问题讨论】:

    标签: swift macos fullscreen


    【解决方案1】:

    我尝试使用 Swift 2 从显示单个窗口的场景中调用 window.contentView?.enterFullScreenMode 进行了一些尝试。更糟糕的是,我只是得到了一个空白屏幕并且 Mac 被锁定了。调用 .exitFullScreenMode 甚至 .toggleFullScreen 都不会恢复。

    我找到了 .toggleFullScreen 的原始问题的原因,在转换到全屏期间我调用了 window.setFrame。调用来自具有调整大小的委托方法。在过渡期间使用 .setFrame 在普通显示器上运行良好,但在 iPad 上不能使用 sidecar。 暂停 .setFrame 直到调用 windowDidEnterFullScreen() 委托解决了问题。

    在我看来 .toggleFullScreen 是目前与 SwiftUI 一起使用的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-30
      • 2020-12-22
      相关资源
      最近更新 更多