NSComboBoxCell吃mouseUp事件

Cor*_*ier 5 macos cocoa appkit nscell

我有一个NSPopover的NSComboBox子项.弹出窗口是瞬态的,并配置为当用户在其边界外单击时关闭.

当其组合框弹出窗口处于活动状态并显示时,当用户按下弹出窗口拥有视图​​时,视图会按预期接收鼠标,弹出框消失,组合框解除,但视图从未接收到下一个mouseUp.

事实证明,NSComboBoxCell的trackMouse方法(跟踪循环)在收到mouseUp之前不会返回,但与mouseDown的情况不同,它将它很好地重新分配到被点击的视图,它从不传播mouseUp.

我不得不使用以下NSComboBoxCell tr​​ackMouse覆盖来解决此问题.

有没有人事先看过这个问题或了解可能发生的事情?

--------

- (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame
            ofView:(NSView *)controlView untilMouseUp:(BOOL)untilMouseUp {

    BOOL trackingResult = [super trackMouse:theEvent inRect:cellFrame
        ofView:controlView untilMouseUp:untilMouseUp];

    // If we were dismissed due to mouse event and the current
    // event (that NSComboBoxCell is currently eating), just redispatch
    // it so it lands with its intended destination.
    if (trackingResult) {
        NSEvent* currentEvent = [NSApp currentEvent];
        if (currentEvent.type == NSLeftMouseUp && currentEvent.window != nil) {
            [NSApp postEvent:currentEvent atStart:YES];
        }
    }

    return trackingResult;
}
Run Code Online (Sandbox Code Playgroud)