Incorrect NSPopover Location Sometimes in El Capitan

I am creating a small state application when I click on the icon that displays NSPopover. Everything worked fine until I switched to El Capitan. The problem is that when I first start the application, I mimic the status bar icon automatically because I want to see a popover and it appears in the lower left corner of the screen. After I close it and open it again, it appears at the top of the screen. Do you see something wrong? This is the code, and when I print the values ​​in showPopover, there is nothing wrong

private let menu = MenuBarController() override init() { super.init() self.menu.onMouseDown = { if (self.menu.iconView?.isSelected == true) { self.showPopover() } else { self.hidePopover() } } } func showPopover() { let icon = self.menu.iconView! let edge = NSRectEdge.MinY let rect = icon.frame self.popover?.showRelativeToRect(rect, ofView: icon, preferredEdge: edge); } func applicationDidFinishLaunching(aNotification: NSNotification) { let icon = self.menu.iconView! icon.mouseDown(NSEvent()) } 

Also, if I simulate an icon, click after a short delay.

+5
source share
1 answer

I had the same problem. Just discovered another solution that does not require delay.

 func applicationDidFinishLaunching(aNotification: NSNotification) { showPopover() // If you only have this, then popover will open in bottom left corner hidePopover() // Adding this showPopover() // and this will open it from the status bar button. } 
0
source

Source: https://habr.com/ru/post/1233926/


All Articles