2013-05-14 77 views

回答

1

一些想法。

  1. 如果您不想在地图上一针,而是一些自定义图像,您可以设置地图的委托,然后写一个viewForAnnotation,做一样的东西:

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
    { 
        if ([annotation isKindOfClass:[CustomAnnotation class]]) 
        { 
         static NSString * const identifier = @"MyCustomAnnotation"; 
    
         // if you need to access your custom properties to your custom annotation, create a reference of the appropriate type: 
    
         CustomAnnotation *customAnnotation = annotation; 
    
         // try to dequeue an annotationView 
    
         MKAnnotationView* annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 
    
         if (annotationView) 
         { 
          // if we found one, update its annotation appropriately 
    
          annotationView.annotation = annotation; 
         } 
         else 
         { 
          // otherwise, let's create one 
    
          annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation 
                      reuseIdentifier:identifier]; 
    
          annotationView.image = [UIImage imageNamed:@"myimage"]; 
    
          // if you want a callout with a "disclosure" button on it 
    
          annotationView.canShowCallout = YES; 
          annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    
          // If you want, if you're using QuartzCore.framework, you can add 
          // visual flourishes to your annotation view: 
          // 
          // [annotationView.layer setShadowColor:[UIColor blackColor].CGColor]; 
          // [annotationView.layer setShadowOpacity:1.0f]; 
          // [annotationView.layer setShadowRadius:5.0f]; 
          // [annotationView.layer setShadowOffset:CGSizeMake(0, 0)]; 
          // [annotationView setBackgroundColor:[UIColor whiteColor]]; 
         } 
    
         return annotationView; 
        } 
    
        return nil; 
    } 
    
  2. 如果您提供标准标注做到这一点(如上图所示),然后你可以告诉地图你要当用户点击上标注的信息披露按钮做什么:

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
    { 
        if (![view.annotation isKindOfClass:[CustomAnnotation class]]) 
         return; 
    
        // do whatever you want to do to go to your next view 
    } 
    
  3. 如果你真的想绕过其披露按钮标注,而是直接去另一个视图控制器,当你在注释视图标签,你会:

欲了解更多信息,请参阅Annotating Maps位置感知编程指南。

相关问题