我将NSSlider设置为连续模式。因此,随着用户移动滑块,我的action方法被调用了多次。我们只需要对滑块的最后一个值进行撤消注册,就不需要跟踪那么多中间值。我了解可以disableUndoRegistration
在undo manager上关闭撤消注册,然后再使用来重新启用撤消注册,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];
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句