macos - 使用 Dark Transparency 使标题栏和 View Controller 无缝衔接

标签 macos swift titlebar nsvisualeffectview

您好,我一直在网上搜索,找到了关于这个主题的各种有用信息,但似乎都没有用

如果想得到这样的东西 enter image description here

标题栏和窗口其余部分融合的地方。从互联网上得到的代码 iv 到目前为止在我的 viewDidLoad() 中

    self.view.window?.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
    self.view.window?.styleMask = (self.view.window?.styleMask)! | NSFullSizeContentViewWindowMask
    self.view.window?.titlebarAppearsTransparent = true
    self.view.window?.movableByWindowBackground = true

但这并没有做任何事情。我是 Mac 开发新手(通常是 ios),所以感谢所有帮助,谢谢!

最佳答案

创建 NSWindowController 的子类并将您的代码放入 windowDidLoad()。

override func windowDidLoad() {
    super.windowDidLoad()

    // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
    self.window?.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)
    self.window?.styleMask = (self.window?.styleMask)! | NSFullSizeContentViewWindowMask
    self.window?.titlebarAppearsTransparent = true
    self.window?.movableByWindowBackground = true
}

关于macos - 使用 Dark Transparency 使标题栏和 View Controller 无缝衔接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33007134/

相关文章:

swift - 保存 Bool/tableView 复选标记 - 第三次幸运

swift - 气化失败

ios - 如何使用 Swift 从 iOS 访问/流式传输 IP 摄像机(RTSP、ONVIF)

user-interface - JavaFX如何整合标题栏和菜单栏?

python - nfcpy - 检测 USB 串行连接的 PN532

java - 当分离 View 获得焦点时,如何在 Mac OS 上显示主菜单?

c - jni.h 和预期 ‘=’ , ‘,’ , ‘;’ , ‘asm’ 或 ‘__attribute__’ 之前 ‘void’

php - Apache 服务器上的 500 错误 - "AllowOverride not allowed here"

html - 在 Bootstrap 中创建可折叠的标题栏(无导航)

python - (Python 2.7) 获取 UI 标题栏大小