CodexBloom - Programming Q&A Platform

Issues with NSVisualEffectView Blurring in macOS 13.6 When Layer Backed is Enabled

👀 Views: 259 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-13
macos nsvisualeffectview layer-backed ui cocoa swift

I've been working on this all day and I recently switched to I need some guidance on I'm encountering a strange issue with `NSVisualEffectView` on macOS 13.6. I have a custom view that utilizes `NSVisualEffectView` to achieve a frosted glass effect, and I'm trying to enable layer-backed rendering for better performance. However, the blurring effect looks inconsistent when the view is resized or when the window is moved. Specifically, the texture seems to flicker or occasionally disappear altogether, which is not the intended behavior. Here's a simplified version of my implementation: ```swift class CustomView: NSView { private var visualEffectView: NSVisualEffectView! override init(frame frameRect: NSRect) { super.init(frame: frameRect) setupVisualEffectView() } required init?(coder: NSCoder) { super.init(coder: coder) setupVisualEffectView() } private func setupVisualEffectView() { visualEffectView = NSVisualEffectView(frame: self.bounds) visualEffectView.autoresizingMask = [.width, .height] visualEffectView.blendingMode = .behindWindow visualEffectView.material = .bar visualEffectView.state = .active self.addSubview(visualEffectView) self.wantsLayer = true // Enable layer-backed drawing } override func resizeSubviews(withOldSize oldSize: NSSize) { super.resizeSubviews(withOldSize: oldSize) // Trying to keep the visual effect view resized properly visualEffectView.frame = self.bounds } } ``` I've already tried disabling layer-backed drawing by setting `self.wantsLayer = false`, and the blurring effect appears correctly, but I'd like to maintain the performance benefits of layer-backed views. I also checked that my `NSVisualEffectView` material is set correctly. Additionally, I confirmed that there are no conflicting views overlapping the `NSVisualEffectView`. Has anyone experienced similar issues with `NSVisualEffectView` in macOS 13.6 when using layer-backed drawing? Any suggestions on how to resolve the flickering or disappearance issue? Thanks in advance for your help! For reference, this is a production microservice. This is my first time working with Swift latest. Any feedback is welcome! This issue appeared after updating to Swift LTS. What would be the recommended way to handle this? I appreciate any insights! Any ideas what could be causing this?