本文介绍了如何在窗口的标题栏中使用NSVisualEffectView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在OS X Yosemite中,Apple引入了新的类NSVisualEffectView.当前,该类尚未记录,但是我们可以在Interface Builder中使用它.

In OS X Yosemite, Apple introduced a new class NSVisualEffectView. Currently, this class is undocumented, but we can use it in Interface Builder.

如何在窗口的标题栏中使用NSVisualEffectView?

How can I use NSVisualEffectView in the window's title bar?

例如:在Safari中,滚动时,内容显示在工具栏和标题栏的下方,具有震撼和模糊的效果.

Here's example: in Safari, when you scroll, the content appears under the toolbar and titlebar with a vibrance and blur effect.

推荐答案

@sgonzalez的回答迫使我探索了找到了titlebarAppearsTransparent属性的NSWindow.h文件.

@sgonzalez's answer forced me to explore NSWindow.h file where i found titlebarAppearsTransparent property.

所以我们得到:

class BluredWindow: NSWindow {

    override func awakeFromNib() {

    let visualEffectView = NSVisualEffectView(frame: NSMakeRect(0, 0, 300, 180))
    visualEffectView.material = NSVisualEffectView.Material.dark
    visualEffectView.blendingMode = NSVisualEffectView.BlendingMode.behindWindow
    visualEffectView.state = NSVisualEffectView.State.active

    self.styleMask = self.styleMask | NSFullSizeContentViewWindowMask
    self.titlebarAppearsTransparent = true
    //self.appearance = NSAppearance(named: NSAppearanceNameVibrantDark)



    self.contentView.addSubview(visualEffectView)

    self.contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[visualEffectView]-0-|", 
                                                                   options: NSLayoutConstraint.FormatOptions.directionLeadingToTrailing,
                                                                   metrics: nil, 
                                                                   views: ["visualEffectView":visualEffectView]))

    self.contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[visualEffectView]-0-|",
                                                                   options: NSLayoutConstraint.FormatOptions.directionLeadingToTrailing, 
                                                                   metrics: nil, 
                                                                   views: ["visualEffectView":visualEffectView]))

您还可以在IB中设置NSVisualEffectView,它将在标题栏上展开.

Also you can setup NSVisualEffectView in IB it will be expanded on titlebar.

这篇关于如何在窗口的标题栏中使用NSVisualEffectView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 00:25