我想在我的MKMapView而不是小石头上显示图像.有人可以在这里放一些有用的代码,或告诉如何做到这一点?
谢谢!
编辑
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
MKPinAnnotationView *pinView = nil;
if(annotation != mapView.userLocation)
{
static NSString *defaultPinID = @"com.invasivecode.pin";
pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( pinView == nil ) pinView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation reuseIdentifier:defaultPinID];
pinView.pinColor = MKPinAnnotationColorGreen;
pinView.canShowCallout = YES;
pinView.animatesDrop = YES;
pinView.image = [UIImage imageNamed:@"pinks.jpg"]; //as suggested by Squatch
}
else {
[mapView.userLocation setTitle:@"I am here"];
}
return pinView;
}
Run Code Online (Sandbox Code Playgroud)
我期待我的图像pinks.jpg在地图上,固定位置而不是默认的针视图(摇针形状).但我仍然得到了引脚的默认图像.
我在MapView上显示用户头像图像.如果在没有动画的情况下渲染它们,它们似乎正在工作,但是我想为它们的动画制作动画.如果我将pinView.animatesDrop设置为true,那么我将丢失头像并将其替换为pin.如何在不使用针的情况下为我的头像添加动画效果?
这是我正在使用的viewForAnnotation方法:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
MKPinAnnotationView* pinView = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"MyAnnotation"];
if (!pinView) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotation"];
}
else
pinView.annotation = annotation;
//If I set this to true, my image is replaced by the pin
//pinView.animatesDrop = true;
//I'm using SDWebImage
[pinView setImageWithURL:[NSURL URLWithString:@"/pathtosomeavatar.png"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
//Adding a nice drop shadow here
pinView.layer.shadowColor = [UIColor blackColor].CGColor;
pinView.layer.shadowOffset = CGSizeMake(0, 1);
pinView.layer.shadowOpacity = 0.5;
pinView.layer.shadowRadius = 3.0;
return pinView; …Run Code Online (Sandbox Code Playgroud) 我有一堆不需要拖动的MKAnnotations.我设置了这个[pin setDraggable:NO].当我触摸注释并且(意外地)拖出注释时,我遇到了问题,它会立即丢失它的自定义图像并更改回默认的红色图钉.我该如何防止这种情况发生?