如何清除MKMapView缓存?

编程入门 行业动态 更新时间:2024-10-21 23:22:00
本文介绍了如何清除MKMapView缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试加载地图区域,并且没有在第二次或后续加载时调用MKMapView委托方法。没有委托方法viz

I am trying load map region and MKMapView delegate methods are not being called on second or subsequent load. None of the delegate methods viz

- (void)mapViewWillStartLoadingMap:(MKMapView *)mapView; - (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView; - (void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error;

被调用。唯一被调用的方法是

are ever called. The Only methods called are

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated; - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated;

似乎ios4正在缓存mapview tile图像。

It seems that ios4 is caching mapview tiles images.

我在MKMapViewDelegate协议参考文档中找到了这些行。突出显示的行是我的问题。

I found these lines in MKMapViewDelegate Protocol Reference documentation. Highlighted line is my problem.

当加载了与当前请求关联的地图图块时,将调用此方法。 当新的可见区域滚动到视图中并且图块尚不可用时,请求地图图块。对于当前不可见的地图部分,也可以请求地图图块。例如,地图视图可以根据需要加载紧邻当前可见区域的平铺,以便用户处理小平底锅。

This method is called when the map tiles associated with the current request have been loaded. Map tiles are requested when a new visible area is scrolled into view and tiles are not already available. Map tiles may also be requested for portions of the map that are not currently visible. For example, the map view may load tiles immediately surrounding the currently visible area as needed to handle small pans by the user.

我需要在地图之后执行某些操作加载,但由于没有上述任何委托方法被调用,我无法执行所需的功能。有人可以建议修复清除缓存或为此提供替代解决方案吗?我已经尝试过使用此处和这个但我仍然无法使代码正常工作。

I need to perform certain operations after the map is loaded but since none of the above mentioned delegate methods are getting called I am not able to perform desired functionality. Can anyone suggest a fix to either clear the cache or provide an alternative solution for this ? I have already tried using the methods described here and this but I am still not been able to get the code working.

推荐答案

我认为你可以结合 willStartLoadingMap , didFinishLoadingMap 和 regionDidChange ,如下所示:

I think you can couple willStartLoadingMap, didFinishLoadingMap and regionDidChange, like this:

  • in willStartLoadingMap 将 loading 标志设置为true;
  • in didFinishLoadingMap 将加载标志设置为false,并检查是否对捕获屏幕的方法进行了排队调用。如果是这样,请调用它;
  • 在 regionDidChange 中检查 loading 标志和如果设置为false,则调用捕获屏幕的方法。否则,将其排队,以便在地图完成加载时执行。
  • in willStartLoadingMap set a loading flag to true;
  • in didFinishLoadingMap set the loading flag to false and also check if you have a queued call for the method that captures the screen. If so, call it;
  • in regionDidChange check the loading flag and if it's set to false, call the method that captures the screen. Otherwise, queue it so it's executed when the map finishes loading.

这样你就可以确保在瓷砖后捕获屏幕了已加载。

This way you're sure that you capture the screen after the tiles have been loaded.

但是,可以多次调用regionDidChange,因此请确保仅在地图视图发生显着变化时抓取屏幕(您可以比较之前的地图区域/中心和当前地图区域/中心)。

However, regionDidChange may be called many times, so make sure you grab the screen only when the map view changes significantly (you can compare previous map region/center and current map region/center for this).

更多推荐

如何清除MKMapView缓存?

本文发布于:2023-11-26 03:02:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632377.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   MKMapView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!