【问题标题】:Find the touched Area (country)on a UIImageView based on coordinates根据坐标在 UIImageView 上找到被触摸的区域(国家)
【发布时间】:2015-01-31 21:52:02
【问题描述】:

我正在使用带有地球图像的 UIImageView,如果我触摸任何区域示例如果我触摸任何非洲国家,我想触发一个触摸事件并显示它是用户点击的特定国家。我走近了让他在图像上坐标的方法,请给我任何建议,我如何才能在国家/地区获得感动的位置。 提前致谢。

【问题讨论】:

    标签: ios objective-c cocoa-touch uiimageview


    【解决方案1】:

    Portrait 模式下,将 Image 放入 ViewController 的 UIImageView 中

    实施

      override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    
            let  touch = touches.anyObject() as UITouch
            println(touch.locationInView(self.view))
    
        }
    

    结果

    (155.5,164.5)
    

    【讨论】:

    • 谢谢 Mohamed,我已经得到了 x 和 y 的坐标,但是我需要确定触摸区域的颜色,假设该区域是红色并且用户触摸了边框或任何地方该区域的中间
    • 更简单的解决方案,您需要为每个国家/地区存储矩形并进行比较 var Egypt_rect = CGRectMake(0, 10, 100, 100) // 埃及 var India_rect = CGRectMake(10, 100, 200, 100) // 印度 var 存在 = CGRectContainsPoint(Egypt_rect, touch.locationInView(self.view)) ;如果存在 { }
    猜你喜欢
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    相关资源
    最近更新 更多