【问题标题】:want to draw a list of polygons and detect which polygon was selected想要绘制多边形列表并检测选择了哪个多边形
【发布时间】:2012-02-13 08:34:28
【问题描述】:

我正在使用UIBezierPath 类绘制多边形。

我有多边形列表。现在,当我单击任何多边形时,我想检测它是哪个多边形。 我认为您可以在UIMapView 中看到相同的概念。

【问题讨论】:

    标签: iphone ios polygon uibezierpath


    【解决方案1】:

    这个怎么样?

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
    
        CGPoint p = [[touches anyObject] locationInView:self.view];
    
       // UIBezierPath *pathTodetect; Path of the shape that you want to detect. In a for loop you can check for all possible paths. 
    
        if(CGPathContainsPoint(pathTodetect.CGPath,nil, p, NO))
        {    
    
            NSLog(@"touched.");
            // the touch is inside the shape  
        }   
    
    }
    

    【讨论】:

    • 比很多,它工作正常。我从过去 2 天开始工作。我想要最近两天的这段代码。但有一件事是错的。我们必须在那里写 pathTodetect.CGPath。
    • 我也想知道过去两天同样的事情非常感谢你们俩
    • @HeartPAL,krishna 很高兴为您提供帮助。它应该是 pathTodetect.CGPath 我会更新它。谢谢。
    猜你喜欢
    • 2011-12-30
    • 2015-07-24
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多