我正在制作一个使用 MKMapView 的应用程序。我添加了自定义引脚(带图像)。现在,当我放大然后缩小时,引脚会变回默认值(红色)。
这是我的代码:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
static NSString* SFAnnotationIdentifier = @"Kamera";
MKPinAnnotationView* pinView =
(MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:SFAnnotationIdentifier];
if (!pinView)
{
MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:SFAnnotationIdentifier];
annotationView.canShowCallout = NO;
UIImage *flagImage = [UIImage imageNamed:@"pinModer.png"];
CGRect resizeRect;
resizeRect.size = flagImage.size;
resizeRect.size = CGSizeMake(40, 60);
resizeRect.origin = (CGPoint){0.0f, 0.0f};
UIGraphicsBeginImageContext(resizeRect.size);
[flagImage drawInRect:resizeRect];
UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
annotationView.image = resizedImage;
annotationView.opaque = NO;
UIImageView *sfIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"kameraNaprejModra.png"]];
annotationView.leftCalloutAccessoryView = sfIconView;
return annotationView;
}
return nil;
}