我正在尝试了解如何NSLayoutManager
使用 Swift 闭包。我可以成功注册undo
如下:
doThing();
undoManager?.registerUndoWithTarget(self, handler: { _ in
undoThing();
}
undoManager?.setActionName("do thing")
当然,我需要支持redo
相当于撤销的撤销。我可以这样做:
doThing();
undoManager?.registerUndoWithTarget(self, handler: { _ in
undoThing();
undoManager?.registerUndoWithTarget(self, handler: { _ in
doThing();
}
undoManager?.setActionName("do thing")
}
undoManager?.setActionName("do thing")
但现在我需要支持撤销重做......嗯......好的:
doThing();
undoManager?.registerUndoWithTarget(self, handler: { _ in
undoThing();
undoManager?.registerUndoWithTarget(self, handler: { _ in
doThing();
undoManager?.registerUndoWithTarget(self, handler: { _ in
undoThing();
}
undoManager?.setActionName("do thing")
}
undoManager?.setActionName("do thing")
}
undoManager?.setActionName("do thing")
如您所见,它的“乌龟一路向下”。我该如何摆脱这种疯狂?即,在我能找到的所有示例代码中,人们使用代码的选择器版本来注册一种可以自行撤消的方法——这显然不适用于我正在使用的闭包方法......如何使用闭包版本并获得无限撤消/重做?