如何使用MKMapView完成加载委托,可能“完成显示”代表? [英] How to use MKMapView finished loading delegate, possible "finished displaying" delegate?

查看:110
本文介绍了如何使用MKMapView完成加载委托,可能“完成显示”代表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在选择注释时点按保存时,我正在尝试保存地图视图的缩略图。当用户尚未放大该注释时会出现问题,因此尚未加载关闭缩放级别。

I'm attempting to save a thumbnail of a mapview when a user taps save when an annotation has been selected. The problem occurs when the user has not zoomed in on that annotation yet, so the close zoom level has not been loaded.

这是我在用户之后正在做的事情点击保存:

This is what I'm doing after the user taps save:


  1. 将bool保存设置为true

  2. 居中并放大注释(无动画)

  3. 调用mapViewDidFinishLoadingMap委托方法时,如果保存为真:

  4. 在视图外创建UIImage,并且保存。关闭模态视图。

  1. Set a bool "saving" to true
  2. Center and zoom in on the annotation (no animation)
  3. When the mapViewDidFinishLoadingMap delegate method gets called, and if saving is true:
  4. Create an UIImage out of the view, and save it. Dismiss modal view.

然而,当图像被保存并且视图被取消时,实际保存的结果图像仍未完成加载,如我仍然看到带有网格线的卸载地图,如下所示:

However when the image is saved, and the view is dismissed the result image saved actually has not finished loading, as I still see an unloaded map with gridlines as shown below:

我的问题是,在保存此缩略图之前,如何确保地图已完成加载并完成显示?

My question is, how can I ensure the map is finished loading AND finished displaying before I save this thumbnail?

推荐答案

更新:iOS7有新委托,可能已解决此问题。我还没有证实这种或那种方式。

Update: iOS7 has a new delegate which may have fixed this problem. I have not confirmed one way or the other yet.

- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered 

Pre iOS6支持:

Pre iOS6 support:

mapViewDidFinishLoadingMap :似乎是不可靠。我注意到它有时根本不被调用,特别是如果地图图块已经被缓存,有时它被多次调用。

mapViewDidFinishLoadingMap: appears to be unreliable. I notice that it is sometimes not called at all, especially if the map tiles are already cached, and sometimes it is called multiple times.

我注意到,当它被多次调用时,最后一次调用将正确呈现。因此,如果您在用户点击保存后设置2秒计时器,我认为您可以使用此功能。禁用交互以便不会发生任何其他情况,并在计时器启动时启用用户交互。

I notice that when it is called multiple times the last call will render correctly. So I think you can get this to work if you set up a 2 second timer after the user taps save. Disable interactions so that nothing else can happen, and enable user interactions when the timer goes.

如果 mapViewDidFinishLoadingMap 被调用,将来再次重置计时器2秒钟。当计时器最终关闭时,获取地图的快照,它应该是正确的。

If mapViewDidFinishLoadingMap gets called reset the timer again for 2 seconds in the future. When the timer finally goes off, get the snapshot of the map and it should be correct.

您还需要考虑其他回调,例如 mapViewDidFailLoadingMap 。还要在嘈杂的连接上测试它,因为如果需要很长时间来获取磁贴,2秒可能不够长。

You will also want to consider the other callbacks such as mapViewDidFailLoadingMap. Also test this on a noisy connection, since 2 seconds may not be long enough if it takes a long time to fetch the tiles.

- (void)restartTimer
{
    [self.finishLoadingTimer invalidate];
    self.finishLoadingTimer = [NSTimer scheduledTimerWithTimeInterval:2.0
                                                               target:self
                                                             selector:@selector(mapLoadingIsFinished)
                                                             userInfo:nil
                                                              repeats:NO];
}

- (void)userClickedSave
{
    assert(self.saving == NO);
    if (self.saving == NO) {
        self.saving = YES;
        assert(self.finishLoadingTimer == nil);
        self.view.userInteractionEnabled = NO;
        [self restartTimer];
    }
}

- (void)mapLoadingIsFinished
{
    self.finishLoadingTimer = nil;
    [self doSnapshotSequence];
    self.saving = NO;
    self.view.userInteractionEnabled = YES;
}

- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
    if (self.saving) {
        [self restartTimer];
    }
}

这篇关于如何使用MKMapView完成加载委托,可能“完成显示”代表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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