gpt4 book ai didi

ios - 检测 MKPolygon 中的点与 iOS7 (CGPathContainsPoint) 冲突

转载 作者:技术小花猫 更新时间:2023-10-29 10:32:09 26 4
gpt4 key购买 nike

SO question 中我今年早些时候问过,我得到了这段代码:

MKPolygonView *polygonView = (MKPolygonView *)[self.mapView viewForOverlay:polygon];
MKMapPoint mapPoint = MKMapPointForCoordinate(tapCoord);
CGPoint polygonViewPoint = [polygonView pointForMapPoint:mapPoint];

if (CGPathContainsPoint(polygonView.path, NULL, polygonViewPoint, FALSE)) {
// do stuff
}

这在 iOS7 之前都很好用。它现在始终返回 false,并且不会检测路径中的点。

我试图找到说明方法更改的任何文档,但找不到任何文档。

知道它为什么坏了吗?还是新的解决方案?

最佳答案

由于某些原因(可能是错误),path 属性在当前版本的 iOS 7 中返回 NULL

解决方法是根据多边形的构建您自己的CGPathRef
使用此方法,您不需要引用 MKPolygonViewMKPolygonRenderer

例如:

CGMutablePathRef mpr = CGPathCreateMutable();

MKMapPoint *polygonPoints = myPolygon.points;
//myPolygon is the MKPolygon

for (int p=0; p < myPolygon.pointCount; p++)
{
MKMapPoint mp = polygonPoints[p];
if (p == 0)
CGPathMoveToPoint(mpr, NULL, mp.x, mp.y);
else
CGPathAddLineToPoint(mpr, NULL, mp.x, mp.y);
}

CGPoint mapPointAsCGP = CGPointMake(mapPoint.x, mapPoint.y);
//mapPoint above is the MKMapPoint of the coordinate we are testing.
//Putting it in a CGPoint because that's what CGPathContainsPoint wants.

BOOL pointIsInPolygon = CGPathContainsPoint(mpr, NULL, mapPointAsCGP, FALSE);

CGPathRelease(mpr);

这也适用于 iOS 6。
但是,您可能希望仅当叠加 View 的 path 属性返回 NULL 时才进行此手动构建。

关于ios - 检测 MKPolygon 中的点与 iOS7 (CGPathContainsPoint) 冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19014926/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com