1

我正在使用以下代码为图像着色UIBezierPath。有颜色选择器,用户可以从中选择颜色。并使用该颜色贝塞尔路径将绘制在图像上。但是当用户在图像中的某个位置填充颜色时,它会从颜色选择器中选择颜色并再次在同一位置填充颜色。在这种情况下,以前绘制的颜色就在那里。我想删除以前填充的颜色并想填充新颜色。仅当用户在相同位置填充颜色时。在这里,我已经得到了UIBezierPath已经绘制的点。有一种方法UIBezierPath removeAllPoints。但它正在从路径中删除所有点。我只想从 uibezierpath 中删除唯一的接触点。我怎样才能做到这一点?

#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];
}
4

1 回答 1

0

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

于 2012-08-01T10:16:30.767 回答