TextField Can't be Edit after Allow an NSWindow (NSPanel) to float above full screen apps

28 Views Asked by At

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]
  1. 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)
    }
}
  1. 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

  1. TextField can be changed if panel is show
    
  2. configPanel show with cornerRadius
    
0

There are 0 best solutions below