- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id<MKAnnotation>)annotation {
NSLog(@"annotion");
CGSize imgSize;
MKAnnotationView *pinView = nil;
static NSString *defaultPinID = @"pin";
pinView = (MKAnnotationView *)
[self.m_mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
pinView.canShowCallout = NO;
pinView.image = [UIImage imageName:@"blue.jpg"];
return pinView;
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
view.image = [UIImage imageName:@"orange.jpg"]
}
我在mapView上添加了带图像的注释(即蓝色图像)。当我点击注释时,我改变了图像(即橙色图像)。然后我点击另一个注释更改注释(ieorange图像)到(即蓝色图像)并将选定的注释更改为(例如,图像)。任何帮助都将被预测。谢谢提前
答案 0 :(得分:4)
尝试这样,可能会有帮助。
重新加载所有其他注释。
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView (MKAnnotationView *)view{
for (id<MKAnnotation> annotation in mapView.annotations){
MKAnnotationView* anView = [mapView viewForAnnotation: annotation];
if (anView){
anView.image = [UIImage imageNamed:@"blue.jpg"];
}
}
view.image = [UIImage imageName:@"orange.jpg"];
}
试试这个
答案 1 :(得分:1)
for swift 3.0
for annotation: MKAnnotation in mapView.annotations {
let anView = mapView.view(for: annotation)
if (anView != nil)
{
anView?.image = UIImage(named: "home_pin")
}
}
view.image = UIImage(named: "home_pin01")