我试图撤销/重做功能添加到一组触摸..如何构建的iOS /核芯显卡的撤消堆栈
我对这个的touchesBegan代码和感动:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"%s", __FUNCTION__);
mouseSwiped = NO;
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2) {
[self eraseButtonTapped:self];
return;
}
lastPoint = [touch locationInView:self.view];
lastPoint.y -= 20;
[self.undoPath addObject:WHATGOESHERE];
// Remove all paths from redo stack
[self.redoStack removeAllObjects];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
//NSLog(@"%s", __FUNCTION__);
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.view];
currentPoint.y -= 20;
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, brush);
CGContextSetRGBStrokeColor(context, red, green, blue, 1.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(context, currentPoint.x, currentPoint.y);
CGContextStrokePath(context);
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
[self.undoPath addObject:WHATGOESHERE];
UIGraphicsEndImageContext();
NSLog(@"Touches Moved undoPath contains %i objects", [self.undoPath count]);
// Remove all paths from redo stack
[self.redoPath removeAllObjects];
lastPoint = currentPoint;
}
我认为,如果我可以计算如何填充撤消堆栈,那我可以遍历堆栈以撤销重做触摸。也许我都是湿的。我当然希望得到一些帮助...
感谢
..我以前也问过类似的问题,但我已经重新启动该项目以不同的形式作为最后的办法是不能令人满意的。
iOS有一个内置的[撤消体系结构](http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/UndoArchitecture/UndoArchitecture.html)。看看那个? – 2012-04-18 05:48:37
谢谢。我刚刚读了这个。这可能非常有用,但代码片段会很好地完成。我个人觉得从代码学习要比从文档学习要容易得多。 – 2012-04-18 06:19:21
我花了数小时/天的时间来探索这一点。我还没有找到全面的答案。如果我收集一个,我会发布我的解决方案。唯一可以报答我的人的方法是帮助他人。 – 2012-04-18 13:28:12