Annotation Image is replaced by RedPushPin when long press on annotation
Asked Answered
O

2

8

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?

Offing answered 14/2, 2012 at 11:20 Comment(0)
A
23

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.

Alenealenson answered 14/2, 2012 at 11:55 Comment(2)
I also wanted to know, Whether I can put RedPushPin on MKAnnotationView or not?Offing
Since you are using your own image for the annotation view, you should use MKAnnotationView. However, yes, you can have some annotations that are MKAnnotationView and some that are MKPinAnnotationView (don't set image on those). Use a separate reuse id for each class.Alenealenson
M
2

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

view.image = [UIImage imageNamed:@"type2.png"];
Maxilliped answered 28/4, 2012 at 5:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.