Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS mapkit:MKAnnotationView未在MKPolygon内居中_Ios_Mkmapview_Mapkit_Mkannotationview_Mkpolygon - Fatal编程技术网

iOS mapkit:MKAnnotationView未在MKPolygon内居中

iOS mapkit:MKAnnotationView未在MKPolygon内居中,ios,mkmapview,mapkit,mkannotationview,mkpolygon,Ios,Mkmapview,Mapkit,Mkannotationview,Mkpolygon,我有几个MKPolygons,我正在使用rendererForOverlay方法覆盖它们。现在,在每个这样的多边形中,我需要显示注释视图 我注意到注释视图的位置非常不准确。只有当我完全缩放到MKPolygon时,我才能看到位于该MKPolygon中心的注释视图 我尝试设置MKAnnotationView派生类实例的中心,但没有效果 我尝试使用centerOffset属性,但没有效果。我不确定我能传递给它什么样的值来使整个东西在MKPolygon内居中 我使用的是我自己的MKAnnotationV

我有几个MKPolygons,我正在使用rendererForOverlay方法覆盖它们。现在,在每个这样的多边形中,我需要显示注释视图

我注意到注释视图的位置非常不准确。只有当我完全缩放到MKPolygon时,我才能看到位于该MKPolygon中心的注释视图

我尝试设置MKAnnotationView派生类实例的中心,但没有效果

我尝试使用centerOffset属性,但没有效果。我不确定我能传递给它什么样的值来使整个东西在MKPolygon内居中

我使用的是我自己的MKAnnotationView派生子类,不是内置于iOS MKPinAnnotationView之类的。。以下是我对注释实现的看法:

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKUserLocation class]])
    {
        //show default blue dot for user location...
        return nil;
    }

    static NSString *reuseId = @"MapAnnotationID";

    MWAnnotationView *av = (MWAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];

    if (av == nil)
    {
        av = [[MWAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
        av.canShowCallout = NO;

        //note that this my custom UIView derived class to show UI.
        MWMapAnnotationView * mapAnnView = [[[NSBundle mainBundle] loadNibNamed:@"MapAnnotationView" owner:nil options:nil] firstObject];

        mapAnnView.tag = TAG_ANNOTATION;

        [av addSubview:mapAnnView];
        av.centerOffset = CGPointMake(0, -15);
    }
    else
    {
        av.annotation = annotation;
    }

    if (map.region.span.longitudeDelta > MAX_LONGITUDEDELTA / 4)
    {
        av.hidden = YES;
    }
    else
    {
        av.hidden = NO;
    }

    //custom UI elements of my subview
    mapAnnView.labelCapital.text = capital;
    mapAnnView.labelPopulation.text = population;

    if (imageName)
    {
        mapAnnView.imageAnnotation.image = [UIImage imageNamed:imageName];
    }
    else
    {
        mapAnnView.imageAnnotation.image = nil;
    }    

    return av;
}
更新:


事实证明,设置centerOffset没有效果。尝试在viewForAnnotation内的不同点设置它,但没有效果。对于任何想知道的人,我有自己的MKAnnotationView子类,我已经在其中重写了centerOffset setter。使用iOS simulator 8.0版进行测试。

一些屏幕截图可能会有所帮助,但请记住,centerOffset不会随缩放级别自动缩放。它是屏幕点中的固定值。这可能会导致注释显示在错误的位置,具体取决于缩放。由于NDA,我无法获得任何屏幕截图-但总结一下-最初注释显示在多边形的右下角。缩放到最大可能值会将其带到多边形中心。所以你的意思是,没有办法修改CGPoint以匹配多边形中心的CGPoint?假设你使用了默认的红色pin注释,并将其放置在伦敦。当放大到非常近的位置时,大头针的底端将位于伦敦中心,大头针的顶端可能在几条街之外。当放大到很远的地方时,图钉的底端仍将位于伦敦中心,因为其中心偏移量是根据图钉图像精确设置的,但图钉的顶部可能会像苏格兰一样远离几英里。如果对每个注释使用不同的图像,中心偏移可能需要根据图像中心的不同而有所不同。所以基本上我的中心偏移应该是0,-一些帖子建议的值?它从未使我信服。我认为它应该是0,一些_值,因为坐标在伦敦的下方,而注释视图的中心在那里。不过,我现在将尝试几种组合。