2011-11-24 32 views
8

Tôi có pin chú thích tùy chỉnh tại ứng dụng:Tuỳ chỉnh thay đổi chú thích pin mặc định pin đỏ tại vòi dài

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    return [kml viewForAnnotation:annotation type:state]; 
} 

nơi tôi trở lại giao diện tùy chỉnh và làm cho setImage cho annotationView của Dấu vị trí như:

- (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)point type:(int)state 
{ 
    // Find the KMLPlacemark object that owns this point and get 
    // the view from it. 
    for (KMLPlacemark *placemark in _placemarks) { 
     if ([placemark point] == point) 
     { 
      UIButton *disclosureButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure]; 
      [[placemark annotationView] setCanShowCallout: YES];    
      [[placemark annotationView] setRightCalloutAccessoryView:disclosureButton]; 

      if (state == 0) 
      { 
       [[placemark annotationView] setImage:[UIImage imageNamed:@"ic_pin_tour.png"]]; 
      } 
      else 
      { 
       [[placemark annotationView] setImage:[UIImage imageNamed:@"ic_pin_point.png"]]; 
      } 

      return [placemark annotationView]; 
     } 
    } 
    return nil; 
} 

nhưng nếu tôi gõ nhẹ vào ghim chú thích của tôi, nó sẽ thay đổi giao diện thành chế độ xem mặc định của nó (RedPin). Tôi không thể hiểu phương thức nào được gọi khi nhấn lâu. Tôi đã cố gắng chơi với UITapGestureRecognizer, nhưng không tìm ra. Nếu tôi chỉ nhấn vào chốt chú thích, tất cả sẽ hoạt động tốt và chế độ xem ghim chú thích tùy chỉnh của tôi sẽ không biến mất. Bạn có thể thấy ý tôi trong ảnh chụp màn hình này: so useful image with example

Vì vậy, tại sao xuất hiện ghim chú thích trên vòi dài?

Trả lời

23

Vì vậy, nếu bạn muốn sử dụng hình ảnh tùy chỉnh cho chế độ xem chú thích, hãy luôn sử dụng MKAnnotationView chung thay vì một MKPinAnnotationView. Tôi có MKPinAnnotationView tại chỉ một nơi, khi tôi thay thế nó với MKAnnotationView mọi thứ hoạt động đúng bây giờ:

- (MKAnnotationView *)annotationView 
{ 
    if (!annotationView) { 
     id <MKAnnotation> annotation = [self point]; 
     if (annotation) { 
      MKAnnotationView *pin = 
       [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil]; 
      pin.canShowCallout = YES; 
      annotationView = pin; 
     } 
    } 
    return annotationView; 
} 
+0

Cảm ơn. đã giúp tôi rất nhiều. –

+1

Làm việc như quyến rũ. Thực tế là, xem MKPinAnnotation là một lớp con với chế độ xem MKAnnotation với chức năng bạn không muốn. – igraczech

Các vấn đề liên quan