2012-10-21 3 views
0

Je crée une application de peinture, mais si la course d'une ligne d'une couleur et si la course une autre ligne traversant la course précédente, le premier changement de course couleur à la deuxième couleur enter image description hereios traits de peinture peinture d'application écraser

Voici le code J'utilise de la peinture:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 

    previousPoint1 = [touch previousLocationInView:self]; 
    previousPoint2 = [touch previousLocationInView:self]; 
    currentPoint = [touch locationInView:self]; 

    [self touchesMoved:touches withEvent:event]; 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    UITouch *touch = [touches anyObject]; 

    CGPoint point = [touch locationInView:self]; 

    /* check if the point is farther than min dist from previous */ 
    CGFloat dx = point.x - currentPoint.x; 
    CGFloat dy = point.y - currentPoint.y; 

    if ((dx * dx + dy * dy) < kPointMinDistanceSquared) { 
     return; 
    } 

    previousPoint2 = previousPoint1; 
    previousPoint1 = [touch previousLocationInView:self]; 
    currentPoint = [touch locationInView:self]; 

    CGPoint mid1 = midPoint(previousPoint1, previousPoint2); 
    CGPoint mid2 = midPoint(currentPoint, previousPoint1); 
    CGMutablePathRef subpath = CGPathCreateMutable(); 
    CGPathMoveToPoint(subpath, NULL, mid1.x, mid1.y); 
    CGPathAddQuadCurveToPoint(subpath, NULL, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y); 
    CGRect bounds = CGPathGetBoundingBox(subpath); 

    CGPathAddPath(path, NULL, subpath); 
    CGPathRelease(subpath); 

    CGRect drawBox = bounds; 
    drawBox.origin.x -= self.lineWidth * 2.0; 
    drawBox.origin.y -= self.lineWidth * 2.0; 
    drawBox.size.width += self.lineWidth * 4.0; 
    drawBox.size.height += self.lineWidth * 4.0; 

    [self setNeedsDisplayInRect:drawBox]; 
} 

- (void)drawRect:(CGRect)rect { 

    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextAddPath(context, path); 
    CGContextSetLineCap(context, kCGLineCapRound); 
    CGContextSetLineWidth(context, self.lineWidth); 
    CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor); 

    CGContextStrokePath(context); 


    self.empty = NO; 
} 

Tout vous sait ce que je fais mal ou comment puis-je conserver chaque coup indépendants l'un de l'autre?

J'apprécierai vraiment votre aide.

+1

On dirait que vous devez utiliser kCGBlend ... Options sur vos chemins. – CodaFi

+0

Pouvez-vous être plus précis ou comment utiliser kCGBlend et où? – Juan

Répondre

0

Je pense que ce que vous devez faire est de commencer un nouveau chemin lorsque vous changez de couleur. Ne vous contentez pas continuer à ajouter de nouveaux sous-chemins avec la nouvelle couleur sur le même chemin qui avait l'ancienne couleur.

Vous aurez besoin de stocker pour chaque chemin de la couleur, il doit être rendu et ensuite en boucle sur vos chemins dans la méthode drawRect.