pin drop animation
Asked Answered
D

1

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?

Del answered 23/9, 2011 at 12:4 Comment(4)
Are you sure the delegate method is called? did you set theMapView delegate property?Yim
Where do you call this method? I just have an instance of MKMapView in this viewController.Del
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.Eliathan
try this where you have initialize theMapView write down [theMapView setDelegate:self];Inflow
P
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;
}
Patrol answered 23/9, 2011 at 12:20 Comment(5)
Does this method get called by the framework or do I have to call it?Trump
@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.Patrol
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.Lever
@Patrol : 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 outIo
@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.Patrol

© 2022 - 2024 — McMap. All rights reserved.