我已经尝试和搜索了很多,但没有找到解决方案。
我有这张图片的 .png [1]: http://imm.io/1f3DY
如果用户触摸 f.e.在区域 1
我想用颜色填充这个区域。蓝色。
有什么方法可以在代码中找到/创建这些区域并用颜色填充它吗?
我已将 .png 转换为 .svg 并创建了一些贝塞尔路径。将贝塞尔路径存储在数组中并添加手势识别器。这很好用。找到了我所触及的正确道路。可以改变路径的颜色。但只有黑线。我想填补 f.e. 之间的空白。路径 1 和路径 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;
}
最佳答案
您还可以使用洪水填充算法来执行此操作。
关于ios - Objective-C 仅在触摸时填充特定区域的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18191993/