Monotouch MapKit - 注释 - 为泡泡添加按钮

7 iphone mapkit xamarin.ios

任何人都知道是否有一个按钮到注释?

我希望这个位置可以选择 - 所以你可以说..选择位置并通过点击按钮获取该位置的所有事件.

这可能吗?

女://

con*_*fin 13

这是我用于注释的代码,它包含一个位于气泡右侧的按钮.您可以设置IBAction以将新视图推送到堆栈以显示您想要的任何内容

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKPinAnnotationView *pinAnnotation = nil;
    if(annotation != mapView.userLocation) 
    {
        static NSString *defaultPinID = @"myPin";
        pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinAnnotation == nil )
            pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

        pinAnnotation.canShowCallout = YES;

        //instatiate a detail-disclosure button and set it to appear on right side of annotation
        UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinAnnotation.rightCalloutAccessoryView = infoButton;

    }

    return pinAnnotation;
}
Run Code Online (Sandbox Code Playgroud)

  • 除此之外,你还需要实现 - mapView:annotationView:calloutAccessoryControlTapped:delegate方法来处理你在注释标注中的披露按钮上的点击. (4认同)
  • 你为什么要发布`defaultPinID`?您不必释放它.最后发布'pinAnnotation`是没有用的,因为它永远不会被调用. (2认同)

Rya*_*tti 5

我只是在目标c中帮助了其他人,但我确信这个概念与单声道相同.您需要创建一个自定义MKAnnotationView对象和覆盖GetViewForAnnotation(viewForAnnotation在OBJ-c)您MKMapViewDelegate类的方法... 检查出其他问题.

当您创建自定义MKAnnotationView对象时,它基本上是用于地图注释的UIView ...您只需将按钮和其他信息添加到视图中,它将在用户点击注释时显示.

这里有一些委托方法的粗略代码:

public override MKAnnotationView GetViewForAnnotation(
                                         MKMapView mapView,NSObject annotation) {
      var annotationId = "location";
      var annotationView = mapView.DequeueReusableAnnotation(annotationId);
      if (annotationView == null) {
         // create new annotation
         annotationView = new CustomAnnotationView(annotation, annotationId);
      }
      else {
         annotationView.annotation = annotation;
      }
      annotation.CanShowCallout = true;
      // setup other info for view
      // ..........

      return annotationView;
   }
}
Run Code Online (Sandbox Code Playgroud)