我使用创建了一个窗口NSVisualEffectView
获得模糊和圆角。喜欢here https://stackoverflow.com/q/42762856/7517228
问题是当我有时我在窗口中看不到我的按钮NSVisualEffectView
代码。如果我删除代码,则会显示该按钮。出了什么问题?
AppDelegate.swift 中的 NSVisualEffectView 代码:
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
guard let window = NSApplication.shared().windows.first else { return }
let effect = NSVisualEffectView(frame: NSRect(x: 0, y: 0, width: 0, height: 0))
effect.blendingMode = .behindWindow
effect.state = .active
effect.material = .dark
effect.wantsLayer = true
effect.layer?.cornerRadius = 15.0
effect.layer?.masksToBounds = true
window.isOpaque = false
window.backgroundColor = .clear
window.contentView = effect
window.titlebarAppearsTransparent = true
window.titleVisibility = .hidden
}
我在故事板中添加了一些按钮。当我运行该项目时,我看不到任何按钮。
当我删除所有内容时applicationDidFinishLaunching(_ aNotification: Notification)
i.e., NSVisualEffectView
代码,我可以看到按钮。
谁能告诉我发生了什么事吗?
我想我应该纠正你的上一个问题 https://stackoverflow.com/questions/42762856/nswindow-with-round-corners-in-swift只是但我没有。
您正在使用故事板,那么您为什么要创建NSVisualViewEffect
你的代码中的变量?
搜索nsvisualeffectview
在右侧面板(实用程序面板)中搜索按钮等(对象库)。
拖动它并根据您的主视图控制器调整它的大小。
要添加模糊效果和模式,请转到“实用程序面板”中的“属性检查器”
and set window.backgroundColor = .clear
and window.isOpaque = false
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
guard let window = NSApplication.shared.windows.first else { return }
window.isOpaque = false
window.backgroundColor = .clear
}
现在您可以添加按钮、文本字段并运行项目。您可以看到所有添加的元素。
我希望它有帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)