简体   繁体   中英

Make NSPanel always on top

I'm making a bridge for react-native-macos. I need NSPanel with the same behaviour as Spotlight. I programmatically created it, but have questions:

  1. Can't make it always on top (also it should work if app is hidden)
  2. There is NSTextField inside the panel. If I try to hide title panel I can't change the field. Looks like it disabled.
  3. What is the best way to display results (like in the spotlight)
private var panel = NSPanel()
private var textField = NSTextField(frame: NSMakeRect(0,0,400,40))

var frame: NSRect = CGRect(x: 0, y: 0, width: 400, height: 40)
frame.size = NSSize(width: 400, height: 60)
panel.setFrame(frame, display: true)
  
let view: NSView = NSView(frame: frame)
    
myTextField.stringValue = "Some text"
myTextField.isEnabled = true
myTextField.font = NSFont.systemFont(ofSize: 28)
    
view.addSubview(myTextField)

panel.contentView?.addSubview(view)

panel.makeKeyAndOrderFront(panel)
panel.center()

Make it floating

panel.isFloatingPanel = true           // << this one !!
panel.makeKeyAndOrderFront(panel)
panel.center()

This works for me

panel.level = .mainMenu

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM