我经常尝试和搜索,但没有找到解决方案。
我将这张照片作为.png [1]:http://imm.io/1f3DY
如果用户触摸f.e.在1区
我想用颜色f.e填充这个区域。蓝色。
有没有办法在代码中找出/创建这些区域并用颜色填充?
我将.png转换为.svg并创建了一些bezierpathes。将bezierpathes存储在数组中并添加手势识别器。这很好用。我找到了正确的道路。可以改变路径的颜色。但只有黑线。我想填补f.e之间的空间。 path1和path 2.我该怎么做?
//The event handling method
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:[recognizer.view superview]];
location.y = self.view.bounds.size.height - location.y;
for(int i = 0; i< bezierPathes.count; i++)
{
//if([b containsPoint:location])
UIBezierPath* b = bezierPathes[i];
if([[self tapTargetForPath:b] containsPoint:location])
{
[[UIColor redColor] setFill];
[b fill];
[testView setNeedsDisplay];
}
}
}
// this method will let you easily select a bezier path ( 15 px up and down of a path drawing)
- (UIBezierPath *)tapTargetForPath:(UIBezierPath *)path
{
if (path == nil) {
return nil;
}
CGPathRef tapTargetPath = CGPathCreateCopyByStrokingPath(path.CGPath, NULL, fmaxf(35.0f, path.lineWidth), path.lineCapStyle, path.lineJoinStyle, path.miterLimit);
if (tapTargetPath == NULL) {
return nil;
}
UIBezierPath *tapTarget = [UIBezierPath bezierPathWithCGPath:tapTargetPath];
CGPathRelease(tapTargetPath);
return tapTarget;
}