2011-08-23 88 views
8

以下是我希望獲得類似風格的示例自定義標註。我正在考慮從MKAnnotation繼承,但我失去了如何啓動它,我不知道標註的設計是否可以被覆蓋。iOS Mapkit自定義標註

http://1.bp.blogspot.com/_xfo3fwc97Fg/TJ9RZrHVOaI/AAAAAAAAAU4/buhP3q3y0G4/s1600/fmip_locate_20100622.png

任何想法如何實現與內部UI控件這個自定義標註?

編輯:下面是來自以下類似StackOverflow的答案我的代碼:

- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
     return nil; 
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; 
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier]; 
    if(annotationView) 
     return annotationView; 
    else 
    { 
     UIImage *img = [UIImage imageNamed:@"default_thumb.png"]; 

     MKAnnotationView *annotationView = 
      [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier]; 
     annotationView.canShowCallout = YES; 
     annotationView.image = img; 
     annotationView.draggable = YES; 

     /* 
     // change left accessory view button with image 
     UIImageView *leftAccView = [[UIImageView alloc] initWithImage:img]; 
     annotationView.leftCalloutAccessoryView = leftAccView; 

     //include a right button to show more info   
     UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     [rightButton addTarget:self action:@selector(calloutSubMenu:) forControlEvents:UIControlEventTouchUpInside]; 
     [rightButton setTitle:annotation.title forState:UIControlStateNormal]; 
     annotationView.rightCalloutAccessoryView = rightButton;   
     */ 

     return annotationView; 
    } 
    return nil; 
} 

// Customize accessory view 
- (void)mapView:(MKMapView *)mapview annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
{ 
    [mapview deselectAnnotation:view.annotation animated:YES]; 

    PopOverCallout *popOverCallout = [[PopOverCallout alloc]init]; 

    UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:popOverCallout]; 

    self.annotationPopoverController = popOver; 

    popOver.popoverContentSize = CGSizeMake(500, 500); 

    [popOver presentPopoverFromRect:view.bounds inView:view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];  
} 

每當引腳被觸摸,顯示標註正確的

(void)mapView:(MKMapView *)mapview annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 

應該叫什麼名字?但是會發生什麼情況是顯示空白的常規標註。我可能會做錯什麼?

順便說一句:UIViewController子類只有XIB上的標籤,並且非常空白。

+3

請參閱[此類似的問題](http://stackoverflow.com/questions/5582564/how-do-i-display-a-uipopoverview-as-a-annotation-to-the-map-view-ipad/ 5583505#5583505)。 – Anna

+0

謝謝。我想這是一個確切的副本。我可能會刪除這個問題,如果其他職位的解決方案是我正在尋找。 – Bahamut

+0

@Anna Karenina - 你能告訴我爲什麼它仍然顯示一個常規的標註嗎?我添加了我的代碼 – Bahamut

回答

14

睡了幾分鐘後找到答案。使用this爲先導

,我只需要覆蓋

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 

其示出了註釋標註。安娜女士再次感謝您的回答。