的MKMapView regionDidChangeAnimated由用户动作或程序调用 [英] MKMapView regionDidChangeAnimated called by user action or program

查看:919
本文介绍了的MKMapView regionDidChangeAnimated由用户动作或程序调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有它的一些注释的的MKMapView。现在,每次当区域改变我加载新的注解。这工作正常,但如果一些注释是附近的地图视图的边界,你点击就可以了,标注信息窗口弹出和的MKMapView区域移动一点(以便它可以显示很好的窗口),但问题是,也regionDidChangeAnimated被调用并重新加载我的所有注解,当然隐藏的信息窗口。
我知道你只需轻按注释再次当它重新加载,但用户似乎打破,你也重新加载注释时,你不需要。

有没有什么办法来检查是否regionDidChangeAnimated被称为因用户操作或编程?

谢谢你。


I have a MKMapView with some annotations in it. Now, every time when the region changes I load new annotations. That works fine, but if some annotation is near border of the map view and you tap on it, the annotation info window pops out and the mkmapview region moves a little (so that it can show the window nicely), but the problem is that also the regionDidChangeAnimated is called and it reloads all my annotations and of course hides the info window.
I know you can just tap the annotation once again when it's reloaded but for user it seems broken and also you reload annotations when you don't need to.
Is there any way to check whether the regionDidChangeAnimated was called because of a user action or programatically?
Thanks.

推荐答案

在附近的地图视图边缘的注解被窃听,并将其移动地图,以适应标注,事件的顺序是:

When an annotation near the map view edge is tapped and it moves the map to fit the callout, the sequence of events is:


  1. regionWillChangeAnimated 被称为

  2. didSelectAnnotationView 被称为

  3. regionDidChangeAnimated 被称为

  1. regionWillChangeAnimated is called
  2. didSelectAnnotationView is called
  3. regionDidChangeAnimated is called

使用两个 BOOL 伊娃标志,你可以在 regionDidChangeAnimated

Using two BOOL ivar flags, you can watch for this sequence and prevent the re-loading of annotations in regionDidChangeAnimated.

例如:

-(void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
{
    regionWillChangeAnimatedCalled = YES;
    regionChangedBecauseAnnotationSelected = NO;
}

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    regionChangedBecauseAnnotationSelected = regionWillChangeAnimatedCalled;
}

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
    if (!regionChangedBecauseAnnotationSelected) //note "!" in front
    {
        //reload (add/remove) annotations here...
    }

    //reset flags...
    regionWillChangeAnimatedCalled = NO;
    regionChangedBecauseAnnotationSelected = NO;
}

这篇关于的MKMapView regionDidChangeAnimated由用户动作或程序调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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