代码之家  ›  专栏  ›  技术社区  ›  Matt S.

只有在触摸特定颜色时才让UITouch执行任务

  •  2
  • Matt S.  · 技术社区  · 16 年前

    如何让UITouch只在UIImage视图中触摸某个颜色时才能识别和执行某个任务。

    例如:

    我有一个街道的图像。这条街有灰色的建筑物和一条白色的路。如果我触摸到一座建筑物,我不希望发生任何事情,但是如果我触摸到白色的道路,我希望将我触摸到的那部分高亮显示为浅蓝色。

    1 回复  |  直到 16 年前
        1
  •  0
  •   Community Mohan Dere    9 年前
    1. 在图像上捕捉触摸事件
    2. 决定颜色是代表道路还是建筑。

    获取精确的触摸坐标

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
    {
        UITouch *touch = [touches anyObject];
        CGPoint touchPoint = [touch locationInView: imageView];
    
        // Here are your touch coordinates
        touchPoint.x
        touchPoint.y
    }
    

    获取该位置的像素颜色: code to get pixel color .

    确定颜色是否代表道路。

    // 230 used as example, Experiment to find a good value
    if (red >230 && green >230 && blue >230)
    {
        // turn street blue
    }