2012-04-21 2 views
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]; 
} 

답변

0

자세한 내용이 필요합니다. 내 가정에서 원하는 색상으로 선을 그려야하지만, 다음 번에 터치 포인트를 다른 색상으로 바꾸려면 전체 선이 아닌가?

관련 문제