2012-02-14 33 views
8

Tôi đã tạo Tuỳ chỉnh Annotation với sau:chú thích hình ảnh được thay thế bằng RedPushPin khi báo chí dài trên chú thích

-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    MKPinAnnotationView *view = nil; 
    if (annotation != mapView.userLocation) 
    { 
     view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"]; 
     if (!view) 
      view = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"]; 

     if (((CustomAnnotation *)annotation).annotationType == 1) 
     { 
      view.image = [UIImage imageNamed:@"type1.png"]; 
      view.rightCalloutAccessoryView = nil; 
      view.canShowCallout = YES; 
     } 
     else 
     { 
      view.image = [UIImage imageNamed:@"type2.png"]; 
      view.rightCalloutAccessoryView = nil; 
      view.canShowCallout = YES; 
     } 
    } 
return view; 
} 

Vấn đề: Khi người dùng bấm và giữ 2 giây trên bất kỳ hình ảnh Chú thích (type1 hoặc type2) , Hình ảnh được thay thế bằng Red PushPin (Mặc định cho iPhone MKPinAnnotationView).

Tôi muốn tránh sự thay thế này. Làm thế nào tôi có thể làm như vậy?

Trả lời

23

Thay vì khai báo và tạo MKPinAnnotationView, hãy khai báo và tạo đồng bằng MKAnnotationView.

MKPinAnnotationView thích đặt mặc định thành ghim màu đỏ.

+0

Tôi cũng muốn biết, dù tôi có thể đặt RedPushPin trên MKAnnotationView hay không? – Krishna

+1

Vì bạn đang sử dụng hình ảnh của riêng bạn cho chế độ xem chú thích, bạn nên sử dụng MKAnnotationView. Tuy nhiên, vâng, bạn có thể có một số chú thích là MKAnnotationView và một số là MKPinAnnotationView (không đặt hình ảnh trên những chú thích đó). Sử dụng id sử dụng lại riêng cho từng lớp. – Anna

+0

Cảm ơn Anna .... – Krishna

2

Sử dụng didDeselectAnnotationViewdidSelectAnnotationView và chọn lại hình ảnh như bạn đã làm bằng cách: -

view.image = [UIImage imageNamed:@"type2.png"]; 
Các vấn đề liên quan