Annotation Image is replaced by RedPushPin when long press on annotation

你说的曾经没有我的故事 提交于 2019-12-05 21:38:05

问题


I have created Custom Annotation with following:

-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{
    MKPinAnnotationView *view = nil;
    if (annotation != mapView.userLocation)
    {
        view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"];
        if (!view) 
            view = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"];

        if (((CustomAnnotation *)annotation).annotationType == 1)
        {
            view.image = [UIImage imageNamed:@"type1.png"];
            view.rightCalloutAccessoryView = nil;
            view.canShowCallout = YES;
        }
        else
        {
            view.image = [UIImage imageNamed:@"type2.png"];
            view.rightCalloutAccessoryView = nil;
            view.canShowCallout = YES;
        }
    }
return view;
}

Problem: When User press and hold for 2 seconds on any Annotation Image (type1 or type2), Image gets replaced by Red PushPin(Default for iPhone MKPinAnnotationView).

I want to avoid this replacement. How can I do so?


回答1:


Instead of declaring and creating an MKPinAnnotationView, declare and create a plain MKAnnotationView.

The MKPinAnnotationView likes to default to the red pin which is what it's for.




回答2:


Use didDeselectAnnotationView and didSelectAnnotationView and reselect the image as you did by :-

view.image = [UIImage imageNamed:@"type2.png"];


来源:https://stackoverflow.com/questions/9275959/annotation-image-is-replaced-by-redpushpin-when-long-press-on-annotation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!