2

I would like to set a custom image instead of the normal pin on a Map. I also want it to be able to be opened and add the drop annimation for each one.

Any suggestion?

EDIT: Here is all I have

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(ActivityAnnotation *)annotation
{
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
    MKPinAnnotationView* pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
    pinView.animatesDrop=YES;
    pinView.canShowCallout=YES;
    UIImage *image = [UIImage imageNamed:@"Map_Pin"];
    pinView.image = image;
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(-2.5,6,27,30);
    [pinView addSubview:imageView];
    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    rightButton.tag = [activities indexOfObject:annotation.activity];
    [rightButton addTarget:self action:@selector(showDetails:) forControlEvents:UIControlEventTouchUpInside];
    pinView.rightCalloutAccessoryView = rightButton;

    return pinView;
}

Everything works fine, but the original pin keeps getting displayed behind my default image. How can I erase it?

1 Answer 1

6

Try not using MKPinAnnotationView, but instead using MKAnnotationView. The MKPinAnnotationView shows a pins by default and only allows you to customize the color (if I'm not mistaken). The MKAnnotationView allows for custom pin images.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes, but if I use a MKAnnotationView, how can I make the animatesDrop animation?
You then have to animate with a drop yourself. It is a bit annoying to calculate the top of the map coordinates, but it's a simple animation on the frame position.
gist.github.com/2399387 This gist is an example of how I drop my MKAnnotationViews using custom animation.
I had the opposite question. Missed the MKPinAnnontationView.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.