ios - SelectAnnotation 也在 Xamarin IOS 中取消选择

标签 ios xamarin xamarin.ios annotations

我尝试以编程方式选择我的注释。所以在我的自定义 map 渲染器中我使用了这个。

    _iosMap.SelectAnnotation(myAnnotation, true);

myAnnotation 被选中了,但之后就被取消选择了。 (信息窗口显示一秒钟然后消失)我不知道为什么。我的意思是,当用户点击某些区域时,我的程序会向 map 添加注释,然后立即调用 SelectAnnotation 来显示信息窗口。

我试图实现这个solution .

    void OnDidDeselectAnnotationView(object sender, MKAnnotationViewEventArgs e) {
     MKMarkerAnnotationView annotationView = (MKMarkerAnnotationView) e.View;
    
     if (someBoolToDetectUnwantedDeselect) {
      _iosMap.SelectAnnotation(annotationView.Annotation, true);
     }
    }

但是没有用。我的意思是注释被选中(OnDidSelectAnnotationView 方法被触发。)但是信息窗口没有出现。我该如何解决这个问题?

我尝试使用 GestureRecognizerShouldBegin(看到它 here 。)但是在选择、取消选择时 GestureRecognizerShouldBegin 没有触发。

补充:我在这里重现了这个问题。

http://www.mediafire.com/file/s1ahsdum258yqpk/selectannotationproblem.rar/file

当在 map 上除图钉之外的任何位置点击时,CustomMapRenderer 中会触发 SelectAnnotation。信息窗口显示一秒钟然后消失。

当我将其添加到 OnDidDeselectAnnotationView 时

((MKMapView)Control).SelectAnnotation(((MKMapView)Control).Annotations.ElementAt(0), true);

像以前一样,第一次点击就会消失。在第二次、第三次点击时,它工作正常。为什么先?

最佳答案

我通过添加延迟解决了这个问题。

private void OnTap(UITapGestureRecognizer recognizer)
{
   //
    PerformSelector(new ObjCRuntime.Selector("ShowAnnotation"), null, 0.6f);
}

[Export("ShowAnnotation")]
void ShowAnnotation()
{
    ((MKMapView)Control).SelectAnnotation(((MKMapView)Control).Annotations.ElementAt(0), true);
}

关于ios - SelectAnnotation 也在 Xamarin IOS 中取消选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58742551/

相关文章:

xamarin.ios - 是否有用于 Xamarin Stack 的跨平台库来跟踪 Google Analytics 的使用情况?

xamarin.ios - 多个 Visual Studio 连接到 Xamarin iOS 的一台 Mac

ios - 带有 BT.709 矩阵的 H.264 编码视频是否包含任何 Gamma 调整?

iphone - 如何制作类似于 iphone/ipad 启动器屏幕的网格?

android - 使用自定义渲染器强制重绘 Xamarin.Forms View

c# - Xamarin Forms Listview 未显示所有项目

c++ - 我如何使用 boost::test 和 xcode 4 来测试一些 ios c++ 代码?

ios - UITextView 在图像附件上时不可滚动

c# - Math.Sin 给了我奇怪的值(value)观

ios - 如何在 IOS 中删除选择器边框