MapView Custom Pin Image Issue

萝らか妹 提交于 2020-01-01 07:26:22

问题


I have changed my MapView pin image but I am getting this problem that some of the point wont change the pin image and some of them change. Where would be the problem? I have added an example.

My Code:

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;

MKAnnotationView *pinView = nil;


if(annotation != locationMap.userLocation)
{
    static NSString *defaultPinID = @"myPin";

    pinAnnotation = (MKPinAnnotationView *)[locationMap dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if ( pinAnnotation == nil )
        pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

    pinAnnotation.canShowCallout = YES;
    pinAnnotation.animatesDrop = YES;
    pinAnnotation.enabled = YES;
    //pinAnnotation.image = [UIImage imageNamed:@"pin.png"];

    pinView.image = [UIImage imageNamed:@"pin.png"];


    UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinAnnotation.rightCalloutAccessoryView = infoButton;
    }
    return pinAnnotation;

    return pinView;

}


回答1:


Use a regular MKAnnotationView, not the MKPinAnnotationView subclass. Even though you can set the image it isn't guaranteed to stick because it can and will set the pin image back again.



来源:https://stackoverflow.com/questions/18568118/mapview-custom-pin-image-issue

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