【发布时间】:2019-11-07 05:36:43
【问题描述】:
我尝试以编程方式选择我的注释。所以在我的自定义地图渲染器中我使用了这个。
_iosMap.SelectAnnotation(myAnnotation, true);
myAnnotation 被选中了,但之后它被取消选中。 (信息窗口显示了一秒钟,然后消失了)我不知道为什么。我的意思是当用户在某些区域点击时,我的程序会在地图上添加注释,然后它会立即调用 SelectAnnotation 来显示信息窗口。
我试图实现这个solution。
void OnDidDeselectAnnotationView(object sender, MKAnnotationViewEventArgs e) {
MKMarkerAnnotationView annotationView = (MKMarkerAnnotationView) e.View;
if (someBoolToDetectUnwantedDeselect) {
_iosMap.SelectAnnotation(annotationView.Annotation, true);
}
}
但它没有工作。我的意思是注释被选中(OnDidSelectAnnotationView 方法被触发。)但是 infowindow 没有出现。我该如何解决这个问题?
我尝试使用 GestureRecognizerShouldBegin(看到它here。)但是在选择时,取消选择 GestureRecognizerShouldBegin 没有触发。
补充:我在这里重现了这个问题。
http://www.mediafire.com/file/s1ahsdum258yqpk/selectannotationproblem.rar/file
当在 CustomMapRenderer 中除了 pin SelectAnnotation 之外的任何地方点击地图时。信息窗口显示一秒钟,然后消失。
当我将它添加到 OnDidDeselectAnnotationView 时
((MKMapView)Control).SelectAnnotation(((MKMapView)Control).Annotations.ElementAt(0), true);
像以前一样在第一次点击时消失。在第二次,第三次点击它工作正常。为什么要先?
【问题讨论】:
-
您能否在您的自定义渲染器中分享更多代码来重现此问题?我测试了官方样本,
SelectAnnotation在我这边运行良好。 -
我添加了一个链接。谢谢。
-
好的,我稍后会检查并更新您。
标签: ios xamarin xamarin.ios annotations