2013-08-06 1 views
2

을 표시하지 않습니다MKAnnotionView 내가 MKAnnotionView이 실현하는 것이를 만든 콜 아웃

- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    if([annotation isKindOfClass:[MKUserLocation class]]) 
     return nil; 

    NSString *identifier = @"mypin"; 

    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 

    if(annotationView == nil) 
    { 
     annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
     annotationView.canShowCallout = YES; 
     UIImageView *pin = [[UIImageView alloc] initWithImage:[UIImage imageNamed:identifier]]; 
     UIImageView *shadow = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pin_shadow"]]; 
     shadow.frame = CGRectMake(21, 36, 60, 27); 

     [annotationView addSubview:shadow]; 
     [annotationView addSubview:pin]; 

     UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
     btn.frame = CGRectMake(0, 0, 11, 20); 
     [btn setImage:[UIImage imageNamed:@"arrow"] forState:UIControlStateNormal]; 

     annotationView.rightCalloutAccessoryView = btn; 
     annotationView.centerOffset = CGPointMake(-(44.0f/2), -62.0f); 
    } 

    return annotationView; 
} 

핀과 그림자가지도에 잘 표시하지만 난 핀을 누를 때 선이 이제 표시됩니다. 주석 객체에는 제목과 부제 값이 있다는 것이 긍정적입니다.

MKAnnotionView에서 .image 속성을 사용하여 핀을 추가하면 작동하지만 내 그림자는 핀 위에 있습니다. mehh! :/

무엇이 잘못 되었나요?

답변

2

이미지를 annotationView의 하위보기로 추가하고 이미지 설정기를 사용하지 않으므로 annotationView의 프레임은 CGRectZero입니다. (clipToBounds를 true로 활성화하여 쉽게 확인할 수 있습니다.) 따라서 핀이 이벤트를 수신하고 콜 아웃을 표시 할 hitZone이 없습니다. annotationView의 경계를 두 이미지 (pin + shadow)의 총 크기로 설정할 수 있습니다. 관련이없는 노트에

annotationView.bounds = CGRectMake(0, 0, pin.frame.size.width, pin.frame.size.width); 
//+Shadow ? if not : annotationView.bounds = pin.bounds; 

, 나는 주석을 재사용 할 때 annotationView에 주석을 재설정하지 않는 한 당신은 문제가 발생할 수 있습니다 생각합니다.

if(annotationView ==nil) { } 
annotationView.annotation = annotation; 
return annotationView; 
으로 변경할 수 있습니다.