2011-08-23 92 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 

其示出了注释标注。安娜女士再次感谢您的回答。