2011-03-02 8 views
1

내 코드는 - (MKAnnotationView *) mapView : (MKMapView *) mapView viewForAnnotation : (id) 주석 방법입니다. 메서드가 호출되고 있지만 pinView.animatesDrop = YES 및 pinView.canShowCallout = YES가 작동하지 않습니다.iphone pinView.animatesdrop not working

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

참조하십시오 도와주세요 :

나는 class.mapView.delegate=self에 대한 대리자를 설정하지 않았다;

+0

이 질문/답변은 다른 사람에게 유용 할 수 있습니까? 그렇지 않다면 삭제하는 것이 좋습니다. – Benjol

+0

예, 유용 할 수 있습니다. 그처럼 단순하지만 사소한 일들을 놓치지 않으려 고 – Droidme

+0

ok, 어느 것이 올바른 대답인지,이 하나입니까, 아니면 @ Mayur입니까? 그것이 그의 것이라면, 나는 당신의 고백을 그의 대답에 대한 논평으로두고 이것을 삭제할 것을 제안 할 것입니다. – Benjol

0

나는 내 문제가 무엇인지 밖으로 일이 블로그 내

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

도움 주셔서 감사합니다. – Droidme