【问题标题】:Custom annotation pin changes to default red pin at long tap自定义注释引脚在长按时更改为默认的红色引脚
【发布时间】:2012-01-05 15:09:03
【问题描述】:

我在应用中有自定义注释引脚:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    return [kml viewForAnnotation:annotation type:state];
}

我返回自定义视图并为 Placemark 的 annotationView 制作 setImage,例如:

- (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)point type:(int)state
{
    // Find the KMLPlacemark object that owns this point and get
    // the view from it.
    for (KMLPlacemark *placemark in _placemarks) {
        if ([placemark point] == point) 
        {
            UIButton *disclosureButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure]; 
            [[placemark annotationView] setCanShowCallout: YES];            
            [[placemark annotationView] setRightCalloutAccessoryView:disclosureButton];

            if (state == 0)
            {
                [[placemark annotationView] setImage:[UIImage imageNamed:@"ic_pin_tour.png"]];
            }
            else
            {
                [[placemark annotationView] setImage:[UIImage imageNamed:@"ic_pin_point.png"]];
            }

            return [placemark annotationView];
        }
    }
    return nil;
}

但是如果我长按我的注释图钉,它的外观会更改为默认视图 (RedPin)。 我不明白长按时调用了什么方法。我尝试使用 UITapGestureRecognizer,但没有发现。如果我只是点击注释针,一切正常,我的自定义注释针视图不会消失。 您可以在此屏幕截图中看到我的意思:

那么,为什么长按时注释针的外观会发生变化?

【问题讨论】:

    标签: iphone ios google-maps mkmapview mkpinannotationview


    【解决方案1】:

    因此,如果您想为注释视图使用自定义图像,请始终使用通用 MKAnnotationView 而不是 MKPinAnnotationView。 我只有一个地方有 MKPinAnnotationView,当我用 MKAnnotationView 替换它时,现在一切正常:

    - (MKAnnotationView *)annotationView
    {
        if (!annotationView) {
            id <MKAnnotation> annotation = [self point];
            if (annotation) {
                MKAnnotationView *pin =
                    [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
                pin.canShowCallout = YES;
                annotationView = pin;
            }
        }
        return annotationView;
    }
    

    【讨论】:

    • 作为魅力。事实上,MKPinAnnotation 视图是 MKAnnotation 视图的子类,具有您不想要的功能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    • 2016-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多