简体   繁体   English

菜单栏图标的菜单的菜单与菜单栏本身保持重叠

[英]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: 更新1:

    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: 更新2:

this worked statusItem = NSStatusBar.system.statusItem(withLength:NSStatusItem.squareLength) statusItem?.menu = menuBarIconMenu 这项工作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? 您是如何分配NSMenu的? I would suggest that you assign your NSMenu to the menu property of the NSStatusItem. 我建议您将NSMenu分配给NSStatusItem的menu属性。 Then you do not have to add code manually to open the menu. 然后,您不必手动添加代码即可打开菜单。 DO you have a custom NSView instance assigned to your NSStatusItem? 您是否为您的NSStatusItem分配了自定义NSView实例?

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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