NSStatusItem fullscreen issues

2019-04-09 17:22发布

问题:

I'm making a statusbar app that displays an NSPopover when the NSStatusItem is clicked, like this:

I have added the ability to resize the popover by dragging on the edges, by subclassing the popover's view like this:

class CMView: NSView {
    let tolerance : CGFloat = 10
    var state = false

    override func mouseDown(theEvent: NSEvent) {
        let point = self.convertPoint(theEvent.locationInWindow, fromView: nil)
        if (point.y <= tolerance) {
            state = true
        }
    }
    override func mouseDragged(theEvent: NSEvent) {
        if (state) {
            let point = self.convertPoint(theEvent.locationInWindow, fromView: nil)
            self.frame = NSRect(
                x: self.frame.origin.x,
                y: self.frame.origin.y,
                width: self.frame.size.width,
                height: self.frame.size.height-point.y)
            popover.contentSize = self.frame.size
        }
    }
    override func mouseUp(theEvent: NSEvent) {
        state = false
    }
}

This only works if the desktop isn't in full screen. If I try to resize it in fullscreen, it simply doesn't work, and the popover arrow disappears mysteriously.

It seems like the popover isn't redrawing when invoked in a fullscreen environment. Is there any way around this problem?

回答1:

Here at WWDC. Asking the same question. You have to have an app that's an UIElement app - meaning no dock icon, no main menu.