iphone pinView.animatesdrop not working

2.3k views Asked by At

Here is my code of - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation method. The method is getting called but the pinView.animatesDrop = YES and pinView.canShowCallout = YES is not working. Please help

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{
    MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@","];
    NSLog(@"pin map");
    if(pinView == nil) 
    {
        pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@""];

        pinView.animatesDrop = YES;
        pinView.canShowCallout = YES;

        UIImage *image = [UIImage imageNamed:@"ann.png"];

        CGRect resizeRect;

        resizeRect.size = image.size;
        CGSize maxSize = CGRectInset(self.view.bounds,
                                     [map annotationPadding],
                                     [map annotationPadding]).size;*/
        maxSize.height -= self.navigationController.navigationBar.frame.size.height + [map calloutHeight];
        if (resizeRect.size.width > maxSize.width)
            resizeRect.size = CGSizeMake(maxSize.width, resizeRect.size.height / resizeRect.size.width * maxSize.width);
        if (resizeRect.size.height > maxSize.height)
            resizeRect.size = CGSizeMake(resizeRect.size.width / resizeRect.size.height * maxSize.height, maxSize.height);

        resizeRect.origin = (CGPoint){0.0f, 0.0f};

        UIGraphicsBeginImageContext(resizeRect.size);
        [image drawInRect:resizeRect];
        UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        pinView.image = resizedImage;
        pinView.opaque = NO;

        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton addTarget:self
                        action:@selector(showDetails:)
              forControlEvents:UIControlEventTouchUpInside];
        pinView.rightCalloutAccessoryView = rightButton;

        if (annotation == mapView.userLocation)
        {
            return nil;
        }
        return pinView;
    } 
    else 
    {
        pinView.annotation = annotation;
    }

    return pinView;
}
2

There are 2 answers

4
Droidme On BEST ANSWER

I worked out what my problem was:

I had not set the delegate for the class.mapView.delegate=self;

0
Mayur Birari On

please see this blog-

here


- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation
{
    NSLog(@"welcome into the map view annotation");

    // if it's the user location, just return nil.
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    // try to dequeue an existing pin view first
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
    MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
                                     initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
    pinView.animatesDrop=YES;
    pinView.canShowCallout=YES;
    pinView.pinColor=MKPinAnnotationColorPurple;


    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    [rightButton addTarget:self
                    action:@selector(showDetails:)
          forControlEvents:UIControlEventTouchUpInside];
    pinView.rightCalloutAccessoryView = rightButton;

    UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"profile.png"]];
    pinView.leftCalloutAccessoryView = profileIconView;
    [profileIconView release];


    return pinView;
}