如何清除MKMapView缓存? [英] How to clear MKMapView cache?

查看:124
本文介绍了如何清除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缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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