iPhone MapKit: Annotation images get reset back to

2019-01-28 05:48发布

I'm adding several annotations to a MapView and using a custom image instead of the default pins. I am using the viewForAnnotation delegate method to set the custom image like this:

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

And I've also tried:

[(MKPinAnnotationView *)view setImage:[UIImage imageNamed:@"placemark.png"]];

Now, these both set the image just fine. But when an annotation is either tapped or the mapType changes to Satellite or Hybrid, it resets back to the red pin image. What am I missing?

3条回答
地球回转人心会变
2楼-- · 2019-01-28 06:14

Don't use MKPinAnnotationView - just use MKAnnotationView.

查看更多
时光不老,我们不散
3楼-- · 2019-01-28 06:21
MKAnnotationView* pinView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];

pinView.animatesDrop=YES;
pinView.canShowCallout=YES;
pinView.image=[UIImage imageNamed:@"userMain.png"];

Don't give MKPinAnnotation its takes default pin annotation. Use only MKAnnotationView object and don't use:

pinView.animatesDrop=YES;
查看更多
ら.Afraid
4楼-- · 2019-01-28 06:31

I think I got it. I ended up having to subclass MKAnnotationView.

查看更多
登录 后发表回答