如何删除或覆盖iPhone中的触摸点bezierpath?

问题描述:

我正在使用以下代码使用UIBezierPath为图像着色。有颜色选择器,用户可以从中选择颜色。随着颜色的不断变化,将会在图像上绘制更多的路径。但是,当用户在图像中的某个位置填充颜色后,从颜色选择器中选择颜色并再次在同一位置填充颜色。在这种情况下,以前绘制的颜色在那里。我想删除以前填充的颜色并希望填充新的颜色。这只在用户在同一位置填充颜色时才有效。在这里我已经得到UIBezierPath已经绘制的点。有一种方法UIBezierPath removeAllPoints。但它会从路径中移除所有点。我只想从uibezierpath中删除只有触及的点。我怎样才能做到这一点?如何删除或覆盖iPhone中的触摸点bezierpath?

#import "MyLineDrawingView.h" 


@implementation MyLineDrawingView 
@synthesize selImage; 
- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) 
    { 

     arrBezierPaths=[[NSMutableArray alloc]init ]; 
     globalPath=[[UIBezierPath alloc]init]; 

     myPath=[[UIBezierPath alloc]init]; 

     self.userInteractionEnabled = TRUE; 

     myPath.lineWidth=30; 
     brushPattern=[UIColor redColor]; 
     NSLog(@"initWithFrame method called"); 
     NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:myPath,@"Path",brushPattern,@"Color", nil]; 
     [arrBezierPaths addObject:dict]; 

    } 
    return self; 
} 


- (void)drawRect:(CGRect)rect 
{ 

    for (int i=0; i<[arrBezierPaths count]; i++) 
    { 
     NSDictionary *dict=[arrBezierPaths objectAtIndex:i]; 
     UIColor *tempBrushpatter=[[UIColor alloc]init ]; 
     tempBrushpatter=[dict valueForKey:@"Color"]; 

     globalPath=[dict valueForKey:@"Path"]; 

     [globalPath strokeWithBlendMode:kCGBlendModeOverlay alpha:1.0]; 
     [tempBrushpatter setStroke]; 

    } 

    } 

#pragma mark - Touch Methods 
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 

    UITouch *mytouch=[[touches allObjects] objectAtIndex:0]; 

    [globalPath moveToPoint:[mytouch locationInView:self]]; 

} 
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 

UITouch *mytouch=[[touches allObjects] objectAtIndex:0]; 
     CGPoint pointTouched = [mytouch locationInView:self]; 

for(int i=0;i<[arrBezierPaths count];i++) 
{ 
    NSDictionary *dictTemp=[arrBezierPaths objectAtIndex:0]; 
    UIBezierPath *temppath=[dictTemp valueForKey:@"Path"]; 
    if([temppath containsPoint:pointTouched]) 
    { 

     // [tempPath removeAllPoints]; 
     NSLog(@"This point already contain some path"); 
    } 
} 
    [globalPath addLineToPoint:[mytouch locationInView:self]]; 

[self setNeedsDisplay]; 
} 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 

} 
-(void)changeColor:(UIColor *)color 
{ 
    UIBezierPath *temp=[[UIBezierPath alloc]init]; 

    // self.userInteractionEnabled = TRUE; 

    temp.lineWidth=30; 
    UIColor *brushColor=color; 

    NSDictionary *dict=[NSDictionary dictionaryWithObjectsAndKeys:temp,@"Path",brushColor,@"Color", nil]; 
    [temp release]; 
    [arrBezierPaths addObject:dict]; 
    brushPattern=[color retain]; 
    [self setNeedsDisplay]; 
} 

需要一些更多的细节。根据我的假设,您正在绘制所需颜色的线条,但下一次您只是想用另一种颜色替换触点,而不是整条线?