繁体   English   中英

Swift-NSMenu Item Popover没有获得焦点

[英]Swift - NSMenu Item Popover doesnt get Focus

所以我遇到一个奇怪的问题,这很难解释,但是我会尽力的。

我有一个状态菜单项:

let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-2)

它包含一个NSMenu:

        let menu = NSMenu()
        statusItem.menu = menu }

现在,我向其中添加自定义Menue项,其中可以包含Button或我想要的任何内容:

    var newController = storyBoard!.instantiateControllerWithIdentifier("testViewController") as! testCustomViewController
    var menueItem = NSMenuItem(title: title, action: action, keyEquivalent: key)
    menueItem.view = newController.view
    statusItem.menu?.addItem(menueItem)

之后,我将testButton放入菜单,然后让他调用Action。

    @IBAction func testClick(sender: NSButton) {
    appDelegate.testPopover(sender)
}

到目前为止,所有作品都很棒,而且按照意向,我可以与所有事物进行互动,并且一切都很好而且很酷。 我可以单击图标,菜单将打开并显示我想要的任何内容。

但是现在到问题了。 如果我在按钮上打开一个Popover(效果很好)并且Popover已打开,则我无法与Popover进行交互。 我仍然可以与菜单和按钮进行交互,一切都很棒。 但是,一旦我单击Popover,一切都会隐藏起来。 (它不会崩溃或发生什么,它只是关闭弹出窗口,菜单等)

我这样打开Popover。 在初始化中:

let Popover = NSPopover()
Popover.contentViewController = storyBoard!.instantiateControllerWithIdentifier("test") as! NSViewController

在testPopoverMethod中:

Popover.showRelativeToRect(button.bounds, ofView: button, preferredEdge: NSMinYEdge)

所以我尝试了很多东西,例如“ resignFirstResponder”,“ becomeFirstResponder”和ofc,我试图改变行为,但是我无法解决此问题。

这是一个截图http://imgur.com/Wj95eQw,如果我在Popover中的任何位置单击,所有内容都将隐藏,无论在哪里,如果有Button或Text字段,都不会有任何区别...

我怎样才能解决这个问题 ?

尝试

func testPopover(sender: AnyObject?) {
        NSRunningApplication.currentApplication().activateWithOptions(NSApplicationActivationOptions.ActivateIgnoringOtherApps)
        Popover.showRelativeToRect(button.bounds, ofView: button, preferredEdge: NSMinYEdge)
    }

暂无
暂无

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

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