简体   繁体   中英

menu for menubar icon's menu keeps overlaping the menubar itself

在此处输入图片说明

 menuBarIconMenu.popUp(positioning: menuBarIconMenu.item(at: 0), at: NSPoint(x: 1842, y: 1414), in: nil)

i use this code to make the menu open and yet it wont be behind the menu bar like all the other menus any way to have it go behind the menubar?


update1:

    statusItem =   NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength)

    menuBarMenuIcon = (statusItem?.button)!; menuBarMenuIcon.image = NSImage(named: "MenuBarButton"); menuBarMenuIcon.action = #selector(menuBarMenuClicked); menuBarMenuIcon.sendAction(on:    [.leftMouseUp,.rightMouseUp])

this is how i assign the menu

update 2:

this worked statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength) statusItem?.menu = menuBarIconMenu

In a previous version of one of my apps, I also opened the menu manually by calling the popup function and experience similiar problems. How did you assign the NSMenu? I would suggest that you assign your NSMenu to the menu property of the NSStatusItem. Then you do not have to add code manually to open the menu. DO you have a custom NSView instance assigned to your NSStatusItem?

private let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)

func applicationDidFinishLaunching(_ aNotification: Notification)
{
    self.statusItem.menu = self.createMenu()
}

private func createMenu() -> NSMenu
{
    // Close
    let menu = NSMenu()
    menu.addItem(NSMenuItem(title: "Quit", action: #selector(self.quit), keyEquivalent: "q"))

    return menu
}

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