是否可以为MGLPolyline创建自定义弹出窗口? [英] Is it possible to create a custom popup for a MGLPolyline?

查看:74
本文介绍了是否可以为MGLPolyline创建自定义弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在寻找一种方法来制作一个MGLPolyline可贴.我考虑过的一种方法是使用MapBox添加的弹出窗口以使其显示某些内容,但使弹出窗口不可见,这样一来,当对特定行进行录音时,我仍然可以执行某些操作(调用函数).

So I have been looking for a way to make an MGLPolyline tapable. One way I have thought about for doing this would be to use that popup thing that MapBox has added to make it show something, but make the popup invisible that way I can still do something (call function) when a certain line is taped.

当前,当您添加polyline.title 时,当您点击下面的波纹管功能时,它将运行,但是尽管如此或将其设置为空("),则它不会运行

Currently when you add polyline.title then when you tap the bellow function runs, but withough this or setting it to nothing ("") then it does not run

        func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
        // Always allow callouts to popup when annotations are tapped.
        print("ok ran?")
        return true
    }

但是,我一直无法找到一种使弹出窗口不可见或不显示的方法,这样我就可以在将其录音后运行一个函数. 有没有办法做到这一点?还是通常以一种可扩展的方式实现我想做的事情?

However I have been unable to find a way to make the popup invisible or not show up so that I can just run a function when its taped. Is there a way to do this? Or a way in general to achive what I want to do in a scalable way?

更新:

        func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
        // Always allow callouts to popup when annotations are tapped.
        print("ok ran?")
        return false
    }

通过将以上返回值更改为false,似乎可以识别触摸而没有显示任何内容. 这是实现我想要的最好的方法吗? 考虑到有时候我触摸它并不能识别,这看起来并不好.

By changing the above return to false it seemed to recognize the touch without showing anything. Is this the best way to achieve what I want? It does not seem great given that sometimes when I touch it does not recognize.

推荐答案

在点击MGLPolyline时,您正在选择它.即使您已经从annotationCanShowCallout:返回了false,即使可能没有可见的提示,在轻触后仍会选择多段线.这就是为什么您的某些水龙头没有可见动作的原因.这些分接头正在取消选择多义线(再次是不可见的).

When you tap on the MGLPolyline you are selecting it. Even when you have returned false from annotationCanShowCallout: the polyline is selected after a tap even though there is probably no visible cue. This is why some of your taps have no visible action. These taps are deselecting the polyline (again invisibly).

您可以做的是从annotationCanShowCallout:返回false(假设您不希望任何注释都带有标注),并使用另一种委托方法来实现所需的目标.

What you can do is return false from annotationCanShowCallout: (assuming you don't want ANY annotations to have a callout) and use another delegate method to achieve your desired goal.

func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
    return false
}

func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
    print("Tapped")
    mapView.deselectAnnotation(annotation, animated: false)
}

通过立即取消选择注释,您可以将每个水龙头注册为一个选择,从而消除漏掉的水龙头.

By immediately deselecting the annotation you can register each tap as a selection, eliminating the missed ones.

这篇关于是否可以为MGLPolyline创建自定义弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆