Mapbox标注在平移/缩放上移动. [英] Mapbox Callout moving on Pan/Zoom.

查看:326
本文介绍了Mapbox标注在平移/缩放上移动.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照指南此处创建自定义标注意见.我在自定义类中添加了两行:

I have followed the guide here to create custom Callout Views. I added two lines to the custom class:

var dismissesAutomatically: Bool = false
var isAnchoredToAnnotation: Bool = true

在平移和缩放时保持标注视图"显示并保持锚定到注释中时,这些似乎可以完成工作.但是,当用户平移或缩放时,标注"似乎下降了约20个像素.

These seem to do the job when it comes to keeping the Callout View displayed when panning and zooming, and keeping it anchored to the annotation. However, The Callout seems to drop down about 20 pixels when the user pans or zooms.

点击注解但在平移/缩放之前的初始视图:

Initial View when annotation is tapped, but before panning/zooming:

平移/缩放后立即查看:

View immediately after panning/zooming:

推荐答案

从Mapbox API文档中获取isAnchoredToAnnotation:

From the Mapbox API docs for isAnchoredToAnnotation:

一个布尔值,指示是否应将标注视图锚定到相应的注释.您可以通过覆盖-[UIView setCenter:]来调整标注视图的确切位置.如果未实现此可选属性,则标注视图将不会锚定到注释.

A Boolean value indicating whether the callout view should be anchored to the corresponding annotation. You can adjust the callout view’s precise location by overriding -[UIView setCenter:]. The callout view will not be anchored to the annotation if this optional property is unimplemented.

在Swift中,它将是:myView.center =
希望这会有所帮助.

In Swift that would be: myView.center =
Hope this helps.

- 在Mapbox网站上查看此示例,其中介绍了如何实现可拖动的注释.有趣的部分是setDragState方法,其中测试了拖动状态(MGLAnnotationViewDragState).我建议在.dragging情况下以类似于他们实现startDragging()endDragging()功能的方式来实现标注中心坐标更新.

EDIT :- Take a look at this example on the Mapbox website that describes how to implement draggable annotations. The interesting part is in the setDragState method where the drag state (an MGLAnnotationViewDragState) is tested. I'd suggest implementing the callout centre coordinate update in the .dragging case in a similar fashion to the way they have implemented the startDragging() and endDragging() functionality.

这篇关于Mapbox标注在平移/缩放上移动.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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