When I try to configure the following, there is a problem:
let mouseLocation = NSEvent.mouseLocation
configPanel = NSPanel(contentRect: NSRect(x: mouseLocation.x, y: mouseLocation.y - 600, width: 800, height: 600), styleMask: [.nonactivatingPanel,.borderless], backing: .buffered, defer: false)
configPanel.collectionBehavior = [.canJoinAllSpaces,.fullScreenPrimary]
- contentViewController corresponding to the configured TextFiled can not be edited, which is a very difficult point!
struct SearchView: View {
@Binding var searchText: String
@Binding var isStared: Bool
var body: some View {
HStack {
TextField("Search", text: $searchText)
.font(.title)
Image(systemName: isStared ? "star.fill" : "star.fill")
.foregroundColor(isStared ? .yellow : .cyan)
.font(.title)
.onTapGesture {
isStared.toggle()
}
}
.padding([.leading,.trailing], 5)
.padding([.top], 3)
}
}
- contentViewController is straight, I tried NSVisualEffectView and so on to modify still can not be modified!
class CustomPanel: NSPanel {
override func awakeFromNib() {
super.awakeFromNib()
// 创建 NSVisualEffectView
let visualEffectView = NSVisualEffectView()
visualEffectView.material = .popover
visualEffectView.blendingMode = .behindWindow
visualEffectView.state = .active
visualEffectView.layer?.cornerRadius = 18
contentView = visualEffectView
}
}
REF
Allow an NSWindow (NSPanel) to float above full screen apps
-
TextField can be changed if panel is show -
configPanel show with cornerRadius