【发布时间】:2012-04-18 05:45:36
【问题描述】:
我正在尝试为一组触摸添加撤消/重做功能..
我有 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 有一个内置的Undo architecture。看看那个?
-
谢谢。我刚读到这个。它可能非常有用,但代码 sn-p 会很好地完成。我个人发现从代码中学习比从文档中学习要容易得多..
-
我花了几个小时/几天来探索这个。我还没有找到一个全面的答案。如果我收集一个,我会发布我的解决方案。我能回报人们的帮助的唯一方法就是帮助别人..
标签: cocoa-touch ios5 core-graphics