2011-03-02 3 views
1

Voici mon code de - (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id) méthode d'annotation. La méthode est appelée mais le pinView.animatesDrop = YES et pinView.canShowCallout = YES ne fonctionne pas. S'il vous plaît aideriphone pinView.animatesdrop ne fonctionne pas

- (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; 
} 

Répondre

-2

je travaillais sur ce que mon problème était:

Je n'avais pas mis le délégué pour la class.mapView.delegate=self;

+0

Cette question/réponse est-elle susceptible d'être utile pour quelqu'un d'autre? Sinon, vous pourriez envisager de le supprimer ... – Benjol

+0

Oui, cela peut être utile. comme beaucoup manquent sur des choses aussi simples mais triviales – Droidme

+0

ok, auquel cas quelle est la bonne réponse, celle-ci, ou @ Mayur? Si c'est le sien, je suggérerais de mettre votre confession comme commentaire sur sa réponse, et de supprimer celle-ci. – Benjol

0

s'il vous plaît voir ce 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; 
} 

+0

Merci pour l'aide. – Droidme