NSSlider 多次撤销注册

NSSlider multiple undo registrations

我将 NSSlider 设置为连续模式。因此,当用户移动滑块时,我的操作方法会被多次调用。我们只需要对滑块的最后一个值进行撤销注册,我们不需要跟踪那么多中间值。我知道我可以在撤消管理器上使用 disableUndoRegistration 关闭撤消注册,然后使用 enableUndoRegistration 将其重新打开,但是我在哪里调用这些以便我们不进行多次撤消注册?

- (IBAction) changeSpacing:(id) sender {
    self.someValue = [sender floatValue];    
    //do undo registration, I would prefer to do this only for the last
    //value of the slider
    [[[myDocument undoManager] prepareWithInvocationTarget:self] setSomeValue:oldValue]
}

NSEvent可能对你有帮助。

- (IBAction) changeSpacing:(id) sender {
    self.someValue = [sender floatValue];    

    NSEvent *event = [NSApplication sharedApplication].currentEvent;
    if (event.type == NSLeftMouseUp) {
        // end dragging
        [[[myDocument undoManager] prepareWithInvocationTarget:self] setSomeValue:oldValue];
    }
}