0

我有一个绘图应用程序。我想实现撤消/重做。尽管我在存储撤消/重做的原始值和新值时遇到了困难。

使用手势我需要存储一些东西:变换、居中、属性对话框,我需要存储更多、颜色、字体、字体大小、轮廓、轮廓颜色、文本本身等。

我创建了一个NSMutableDictionary用户可以在单个手势/属性弹出窗口中更改的属性。

我想使用Rob 的答案NSUndoManager和旋转手势,尽管使用他的解决方案与 一起使用CGAffineTransform,当作为参数发送时 prepareWithInvocationTarget,它不是对象,只是将CGAffineTransform结构的副本放在撤消/重做堆栈上。

虽然在使用prepareWithInvocationTargetNSMutableDictionary传入的字典时(OriginalAttribs,newAttribs)不会保留。我不能将它们作为本地 iVar,因为它们会随着绘图对象上的每个动作而改变。

似乎我想retainArguments用作其中的一部分,NSInvocation但我真的不想保留它们。我需要他们的副本。

它的手势使这变得困难,因为我无法继续设置 OrigianlCenter, OriginalTransform,因为它在手势处于活动状态时会发生变化。

更新 我找到了这个链接,它似乎与我想做的类似。

我像这样设置我的 NSUndoManager:

        //Needed to get access to UndoManager
    NSUndoManager * undoManager = [(IoScreenEditorViewController * )UIAppDelegate.ioMainViewController.currentViewController undoManager];

        //Need to Store our Center as a NSValue
    [undoManager prepareWithInvocationTarget:self];
    [undoManager forwardInvocation:anInvocation ];

然后我得到一个运行时错误:

 -[NSUndoManager undoAttributesWithOriginalAttributes:newAttributes:]: unrecognized selector sent to instance 0xeedcbd0

undoAttributesWithOriginalAttributes:newAttributes:是我为我的 NSInvocation 对象设置的选择器。根据这里的文档,它说它应该将它传递给自我(目标),而不是撤消管理器自我?

4

0 回答 0