任何人都知道是否有按钮进入注释?
我希望这个位置可以选择 - 所以你可以说..选择位置并通过点击按钮获取该位置的所有事件。
这可能吗?
瓦特://
答案 0 :(得分: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;
}
答案 1 :(得分:5)
我只是在目标c中帮助了其他人,但我确信这个概念与mono相同。您需要创建一个自定义MKAnnotationView对象并覆盖MKMapViewDelegate类的{strong> GetViewForAnnotation (obj-c中的viewForAnnotation)方法... check out the other question。
当您创建自定义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;
}
}