10

The default pin drop animation doesn't work in my app, here is some code I wrote:

- (void)viewDidLoad {
    /*
        some code...
    */
    [theMapView addAnnotation:addAnnotation];
    [addAnnotation release];
}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
    MKPinAnnotationView *annoView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation 
                                                            reuseIdentifier:@"current"];
    annoView.animatesDrop = YES;
    annoView.pinColor = MKPinAnnotationColorGreen;
    return annoView;
}

Right now the pin just appear in the screen as default red one without any animation, the MKMapViewDelegate protocol has been adopted, anyone can see what's wrong here?

4
  • 1
    Are you sure the delegate method is called? did you set theMapView delegate property?
    – viggio24
    Commented Sep 23, 2011 at 12:09
  • Where do you call this method? I just have an instance of MKMapView in this viewController.
    – Michael
    Commented Sep 23, 2011 at 12:13
  • 1
    You will need to control drag from the map to your File's Owner and select delegate. Also control drag from the File's Owner to your MapView to make sure your map can recieve the annotation. Commented Sep 23, 2011 at 12:21
  • 2
    try this where you have initialize theMapView write down [theMapView setDelegate:self];
    – Sonu
    Commented Sep 23, 2011 at 12:25

1 Answer 1

13

First use:

[yourMap_view setDelegate:self];

in ViewDidLoad

Then call this for the drop animation :

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinView = nil;
if(annotation!= map_view.userLocation)
{
    static NSString *defaultPin = @"pinIdentifier";
    pinView = (MKPinAnnotationView*)[map_view dequeueReusableAnnotationViewWithIdentifier:defaultPin];
    if(pinView == nil)
        pinView = [[[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:defaultPin]autorelease];
    pinView.pinColor = MKPinAnnotationColorPurple; //Optional
    pinView.canShowCallout = YES; // Optional
    pinView.animatesDrop = YES;
}
else
{
    [map_view.userLocation setTitle:@"You are Here!"];
}
return pinView;
}
5
  • Does this method get called by the framework or do I have to call it?
    – wwjdm
    Commented Apr 21, 2013 at 22:47
  • @EliMiller, if you set your mapview's delegate. And paste the viewForAnnotation method, it will trigger whenever a map view's annotation is seen on map.
    – iNoob
    Commented May 20, 2013 at 10:02
  • 1
    Information on how to do this is surprisingly sparse but I found this solution to work for me. It's worth noting that the pinColor or canShowCallout properties aren't a requirement. Commented Oct 28, 2013 at 13:29
  • @iNoob : I know its very late. But I am getting prob with drop animation. I implemented ur code, working fine, also dropping pins on proper location, but my issue is, the drop animation is not so smooth. Pins just appears at top and then direct to location. Can't get smooth animation. I am doing this for iOS6. Please help me out
    – Nayan
    Commented Dec 17, 2013 at 6:11
  • @NSS: Not sure about the smooth animation. Maybe it is because the view is "heavy", mapview is pretty memory consuming. If you have time can you just use a sample application with just map and pin drop animation, and test on device if it still not so smooth. Animation is pretty OK on device, as it is handled by OS. Read somewhere maps in iOS 6 are more memory consuming than 5, i don't recall the exact post for links.
    – iNoob
    Commented Dec 18, 2013 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.