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 に答える