Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 14th, 2012  |  syntax: None  |  size: 1.07 KB  |  hits: 89  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. MKPinAnnotationView custom Image is replaced by pin with animating drop
  2. - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
  3.     if ([annotation isKindOfClass:[MKUserLocation class]])
  4.         return nil;
  5.  
  6.     MKPinAnnotationView* pinView = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"MyAnnotation"];
  7.  
  8.     if (!pinView) {
  9.         pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CustomPinAnnotation"];
  10.     }
  11.     else
  12.         pinView.annotation = annotation;
  13.  
  14.     //If I set this to true, my image is replaced by the pin
  15.     //pinView.animatesDrop = true;
  16.  
  17.     //I'm using SDWebImage
  18.     [pinView setImageWithURL:[NSURL URLWithString:@"/pathtosomeavatar.png"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
  19.  
  20.     //Adding a nice drop shadow here
  21.     pinView.layer.shadowColor = [UIColor blackColor].CGColor;
  22.     pinView.layer.shadowOffset = CGSizeMake(0, 1);
  23.     pinView.layer.shadowOpacity = 0.5;
  24.     pinView.layer.shadowRadius = 3.0;
  25.  
  26.     return pinView;
  27. }