我将 NSSlider 设置为连续模式。因此,当用户移动 slider 时,我的操作方法会被多次调用。我们只需要对 slider 的最后一个值进行撤消注册,并且不需要跟踪这么多中间值。我知道我可以在撤消管理器上使用 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];
}
}
关于objective-c - NSSlider 多次撤销注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28941888/