请帮我撤消并转发我的抽奖活动。我将所有路径存储到pathArray中,现在我想撤消路径(如app Notes(Apple))。 请帮帮我解决这个问题!
这是我的PathArray类
// PathArray.h
#import <Foundation/Foundation.h>
@interface PathArray : NSObject
@property (nonatomic) CGPoint start;
@property (nonatomic) CGPoint end;
@property (nonatomic) UIColor* color;
@property (nonatomic) CGFloat pathWidth;
- (instancetype) initWithStartPoint: (CGPoint)start andEnd: (CGPoint)end andColor: (UIColor *) color andPathWidth: (CGFloat) pathWidth;
@end
这是我的Draw课程
- (void)drawRect:(CGRect)rect
{
[strokecolor setStroke];
for (int i=0; i<pathArray.count; i++ ) {
CGContextRef contex = UIGraphicsGetCurrentContext();
CGContextSetLineCap(contex, kCGLineCapRound);
CGContextBeginPath(contex);
CGContextMoveToPoint(contex, pathArray[i].start.x, pathArray[i].start.y);
CGContextAddLineToPoint(contex, pathArray[i].end.x, pathArray[i].end.y);
CGContextSetStrokeColorWithColor(contex, pathArray[i].color.CGColor);
CGContextSetLineWidth(contex, pathArray[i].pathWidth);
CGContextStrokePath(contex);
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch* touch = [touches anyObject];
if ([touch type] == UITouchTypeStylus)
{
if(drawable){
[self.delegate changeScrollViewInteraction:NO];
UITouch *touch = [touches anyObject];
lastPoint = [touch locationInView:self];
}
}
else
{
[self.delegate changeScrollViewInteraction:YES];
return;
}
[super touchesBegan: touches withEvent: event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch type] == UITouchTypeStylus) //pencil touch
{
if(drawable){
CGPoint newpoint = [touch locationInView:self];
PathArray *paths = [[PathArray alloc]initWithStartPoint:lastPoint andEnd:newpoint andColor:strokecolor andPathWidth:pathWidth];
[pathArray addObject:paths];
lastPoint = newpoint;
[self setNeedsDisplay];
NSLog(@"%@",pathArray[0]);
}
}
else
{
return;
}
[super touchesMoved: touches withEvent: event];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if ([touch type] == UITouchTypeStylus && drawable) //pencil touch
{
[pathEndPointArray addObject:tempEndPointArray];
}
if ([touch type] == UITouchTypeStylus && !drawable)
{
[self.delegate CacheLIView_showPopup_message:@"Already cupped!"];
}
[self touchesMoved:touches withEvent:event];
}
-(void)undo{
}
-(void)foward{
}
-(void)re_draw_after_rotate{ }
我需要创建这些功能。
答案 0 :(得分:0)
我建议如下(这里没有代码):
pathUndoArray
pathArray
中移除最后一个条目(如果存在)并将其添加(最后)到pathUndoArray
,然后重新绘制。pathUndoArray
中移除最后一个条目(如果存在)并将其添加(最后)到pathArray
,然后重新绘制。pathUndoArray
您还可以查看NSUndoManager
。