在平移时跟踪MKMapView centerCoordinate [英] Tracking MKMapView centerCoordinate while panning

查看:80
本文介绍了在平移时跟踪MKMapView centerCoordinate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用中实现一个地图功能,我允许用户通过平移来设置他们当前的位置。

I'm implementing a map feature in my app where I allow the user to set their current location by panning around.

这一次,我希望在 centerCoordinate MKAnnotation C $ C>。所以我想要做的是跟踪地图的centerCoordinate何时更改并正确更改注释的坐标。行为类似于 Uber Hailo 和其他行为。

All this time, I want to have an MKAnnotation in the centerCoordinate. So what I want to do is keep track of when the map's centerCoordinate changes and change the annotation's coordinate correctly. The behaviour would be similar to that of Uber, Hailo and others.

我尝试过基于时间的实施将检查每个 0.00001s centerCoordinate ,并且还会移动注释。但是如果地图没有轻轻地轻弹,那么注释就会从一个地方跳到另一个地方,这不会形成一个好的用户界面。

I tried a time based implementation where every 0.00001s the centerCoordinate would be checked and the annotation would also be moved. But if the map isn't flicked gently, the annotation jumps from one place to another which doesn't make for a good UI.

我试过的另一个实现方式是手势识别器和 MKMapView 的委托方法( regionDidChange / regionWillChange )。这又是一个非常突然的转变。

Another implementation I tried is by way of gesture recognisers and the delegate methods of MKMapView (regionDidChange/regionWillChange). This, again, makes for a very abrupt transition.

有人可以告诉我如何做得更好吗?

Can anyone please advise me on how to do this better?

推荐答案

我建议不要使用实际的 id< MKAnnotation> (至少对于这个当前位置设置模式) 。

I suggest not using an actual id<MKAnnotation> at all (at least for this "current location setting" mode).

相反:


  1. 添加视图(例如 UIImageView )包含地图视图 中图钉(或任何您喜欢的图标)的图像。

  2. 此视图应该 是地图视图的子视图。

  3. 引脚视图应该是地图视图是子视图的同一视图的子视图(例如,两者都应该是同一超视图的子视图)。

  4. 引脚视图的大小和位置应使其显示在地图视图的中心上方(您可以使引脚视图与地图视图具有相同的框架和相同的自动布局/自动调整逻辑,以便它们保持可视化同步无论屏幕尺寸或方向如何)。

  5. 如果使用 UIImageView ,请将其内容模式设置为center,将背景颜色设置为clear。

  6. 引脚视图应该禁用用户交互,以便用户仍然可以与其后面的地图视图进行交互。当用户平移或缩放地图视图时,前面的图钉视图似乎会立即移动。

  7. 如有必要,应用程序可以从 mapView获取位置坐标.centerCoordinate regionDidChangeAnimated:委托方法(或平移/捏动手势识别器)中,或仅在用户说他们已完成定位时。我不建议使用计时器(尤其是每0.00001秒)来查询当前的中心坐标。

  8. 当用户指示当前位置是他们想要最终放置注释的位置时,然后,您可以在该坐标处创建并添加实际注释,并隐藏位置设置模式引脚视图。

  1. Add a view (eg. UIImageView) containing an image of a pin (or whatever icon you like) in front of the map view.
  2. This pin view should not be a subview of the map view.
  3. The pin view should be a subview of the same view that the map view is a subview of (eg. both should be subviews of the same superview).
  4. The pin view should be sized and positioned such that it appears above the center of the map view (you could make the pin view have the same frame and the same autolayout/autoresizing logic as the map view so they stay visually synchronized regardless of screen size or orientation).
  5. If using a UIImageView, set its content mode to "center" and background color to "clear".
  6. The pin view should have user interaction disabled on it so that the user can still interact with the map view behind it. As the user pans or zooms the map view, the pin view in front will seem to move instantly.
  7. If necessary, the app can get the location coordinates from mapView.centerCoordinate in the regionDidChangeAnimated: delegate method (or pan/pinch gesture recognizers) or only when the user says they're done positioning. I don't recommend using a timer (especially every 0.00001s) to query the current center coordinate.
  8. When the user indicates that the current position is where they want to finally place the annotation, you can then create and add an actual annotation at that coordinate and hide the "location setting mode" pin view.

这篇关于在平移时跟踪MKMapView centerCoordinate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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