Mapbox Callout moving on Pan/Zoom.

左心房为你撑大大i 提交于 2019-12-11 08:38:15

问题


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

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:


回答1:


From the Mapbox API docs for isAnchoredToAnnotation:

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.

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

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.



来源:https://stackoverflow.com/questions/44379788/mapbox-callout-moving-on-pan-zoom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!