0
내가 페인트 응용 프로그램을 만드는거야하지만 스트로크 한 줄 경우 하나 개의 색상과 뇌졸중 이전의 스트로크에게 두 번째 색상 여기 IOS 응용 프로그램 덮어 페인트
에 대한 첫 번째 스트로크 변경 색상을 건너 또 다른 라인을 경우하는 코드입니다 스트로크 페인트 나는 페인트하는 데 사용하고 있습니다.
- (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;
}
내가 잘못하고있는 것을 알고 있거나 어떻게하면 각 획을 서로 독립적으로 유지할 수 있습니까?
정말 감사드립니다.
경로에 kCGBlend ... 옵션을 사용해야하는 것 같습니다. – CodaFi
kCGBlend를보다 구체적으로 사용하거나 어디에서 사용할 수 있습니까? – Juan