我想使用 NSViewRepresentable 在 SwiftUI 中创建一个模糊视图,但 XCode 给了我一条错误消息,上面写着“在范围内找不到类型 'NSViewRepresentable'”。
import SwiftUI
struct BlurWindow: NSViewRepresentable { //Cannot find type 'NSViewRepresentable' in scope
func makeNSView(context: Context) -> NSVisualEffectView { //Cannot find type 'Context' in scope
let view = NSVisualEffectView() //Cannot find type 'NSVisualEffectView' in scope
view.blendingMode = .behindWindow
return view
}
func updateNSView(_ nsView: NSVisualEffectView, context: Context) { //Cannot find type 'Context' in scope
}
}
但是,当我将这个完全相同的代码复制并粘贴到一个新的全新 Xcode 项目中时,没有错误。我在 Google 和 StackOverflow 上进行了搜索,但没有发现任何人有同样的问题。