Iphone 长点击时,自定义注释接点将更改为默认红色接点

Iphone 长点击时,自定义注释接点将更改为默认红色接点,iphone,ios,google-maps,mkmapview,mkpinannotationview,Iphone,Ios,Google Maps,Mkmapview,Mkpinannotationview,我在应用程序上有自定义注释pin: - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { return [kml viewForAnnotation:annotation type:state]; } -(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释 { 返回[kml view

我在应用程序上有自定义注释pin:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    return [kml viewForAnnotation:annotation type:state];
}
-(MKAnnotationView*)地图视图:(MKMapView*)地图视图注释:(id)注释
{
返回[kml viewForAnnotation:注释类型:状态];
}
其中,我返回自定义视图,并为Placemark的注释视图生成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;
}
-(MKAnnotationView*)视图用于注释:(id)点类型:(int)状态
{
//找到拥有此点的KMLPlacemark对象并获取
//从它看风景。
用于(KMLPlacemark*placemark in_placemarks){
如果([位置标记点]==点)
{
UIButton*DispositionButton=[UIButton Button类型:UIButtonTypedTailDisposition];
[[placemark annotationView]setCanShowCallout:是];
[[placemark annotationView]setRightCalloutAccessoryView:披露按钮];
如果(状态==0)
{
[[placemark annotationView]设置图像:[UIImage ImageName:@“ic_pin_tour.png”];
}
其他的
{
[[placemark annotationView]设置图像:[UIImage ImageName:@“ic_pin_point.png”];
}
返回[placemark annotationView];
}
}
返回零;
}
但如果我长时间点击注释插针,它会将外观更改为默认视图(红色插针)。 我无法理解长点击时调用的是什么方法。我尝试使用UITapGestureRecognitizer,但没有发现。如果我只需点击注释接点,所有操作都正常,并且我的自定义注释接点视图不会消失。 你可以在这个截图中看到我的意思:


那么,为什么注释接点的外观会在长时间点击时发生变化呢?

因此,如果要将自定义图像用于注释视图,请始终使用通用的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;
}
-(MKAnnotationView*)annotationView
{
如果(!annotationView){
id注释=[self point];
如果(注释){
MKAnnotationView*引脚=
[[MKAnnotationView alloc]initWithAnnotation:annotation重用标识符:nil];
pin.canShowCallout=是;
注释视图=引脚;
}
}
返回注释视图;
}

作为一种魅力。事实上,MKPinAnnotation视图是MKAnnotation视图的一个子类,具有您不想要的功能。