我想使用NSUndoManager撤銷並重做繪圖應用程序中的描邊和更改。 我使用UIGraphicsGetImagefromCurrentImageContext()將圖像存儲到可變數組中。重置撤銷/重做陣列iOS
我下面的代碼給出了一個想法:
- (void) performUndoRedo:(BOOL) undo
{
if (undo)
{
[undoManager undo];
}
else
{
[undoManager redo];
}
NSLog(@"layerArray:%@", layerArray);
[self drawImage:[layerArray lastObject]];
}
- (void) redo:(id) object
{
[layerArray addObject:object];
[[undoManager prepareWithInvocationTarget:self] undo:object];
[undoManager setActionName:@"drawredo"];
// NSLog(@"layerArray IN REDO:%@", layerArray);
}
- (void) undo:(id) object
{
[[undoManager prepareWithInvocationTarget:self] redo:object];
[undoManager setActionName:@"drawundo"];
[layerArray removeObject:object];
// NSLog(@"layerArray IN UNDO:%@", layerArray);
}
- (void) touchesEnded:(NSSet *) touches withEvent:(UIEvent *) event
{
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext();
[layerArray addObject:layerImage];
[self undo:layerImage];
UIGraphicsEndImageContext();
NSLog(@"%@", layerArray);
}
如何以及在什麼點動作可以清除layerArray,並重置撤消堆棧?在此先感謝
是否在撤銷重做操作 – Ranjit 2012-07-10 14:28:17
難道ü找到任何解決辦法爲這個成功。我也面臨同樣的問題。如果有人對此有所瞭解,這對我會有所幫助。 – Madhavan 2018-01-10 13:00:17