当在一个的MKMapView被选择的第二注解检测 [英] Detect when a second annotation is selected in a MKMapView

查看:138
本文介绍了当在一个的MKMapView被选择的第二注解检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用地图中选择一个注释,我将展示用的信息,如谷歌地图应用的仰视图。
我展示它在地图上的委托:

When a use selects an annotation in a map, I show a bottom view with informations, such as the google maps app. I'm showing it in the map's delegate :

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view

当用户取消选择(通过地图上的任何地方录音),我躲在我的仰视图。这在相反委托方法完成的:

When the user deselects it (by taping anywhere on the map), I hide my bottom view. This is done in the opposite delegate method :

- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view

它工作得很好,我很高兴。但是,如果用户选择了第二个注释(即:他拿出第一批注,则水龙头一个又一个,没有首先取消注释在此期间的),我不想隐瞒我的底视图然后再次显示它。我只是想改变的信息在里面。

It works well, I'm happy with it. However, if a user selects a second annotation (ie: he taps a first annotation, then taps another one, without deselecting first the annotation in the meantime), I don't want to hide my bottom view then show it again. I'd just like to change informations in it.

不过,由于图形页面:didDeselectAnnotationView:被称为之前 图形页面:didSelectAnnotationView:我无法弄清楚如何检测我上面描述的情况。

However, as mapView:didDeselectAnnotationView: is called before mapView:didSelectAnnotationView:, I can't figure out how to detect the situation I'm describing above.

我的问题是:我怎么可以检测到用户选择了第二个标注或我应该如何以任何其他方式解决这个问题

推荐答案

也许尝试把延迟你didDeselectAnnotationView方法来隐藏自己的bottomView。你需要存储到你最后选定的注解视图的引用虽然。

Maybe try put a delay in your didDeselectAnnotationView method to hide your bottomView. You need to store a reference to your last selected annotation view though.

例如:

@interface MyViewController
{
    MKAnnotationView *lastSelectedAnnotationView;
}

@end


@implementation MyViewController

...

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    ...

    [self updateBottomViewInfoWithAnnotationView:view];

    lastSelectedAnnotationView = view;
}

- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
    // ------------------------------------------------------------------
    // perform check to hide bottomView after a delay, to give
    // didSelectAnnotationView a chance to select new annotation
    // ------------------------------------------------------------------

    [self performSelector:@selector(checkShouldHideBottomView:) withObject:view afterDelay:0.5];
}

-(void)checkShouldHideBottomView:(MKAnnotationView *)lastDeselectedAnnotationView
{
    // ----------------------------------------------------------------------
    // Only hide bottom view if user did not select a new annotation or 
    // last selected annotation is the same as the one being deselected
    // ----------------------------------------------------------------------
    if(lastSelectedAnnotationView == nil || lastDeselectedAnnotationView == lastSelectedAnnotationView)
    {
        // hide your bottom view example
        self.bottomView.alpha = 0;

        // clear lastSelectedAnnotationView reference
        lastSelectedAnnotationView = nil;
    }
}

这篇关于当在一个的MKMapView被选择的第二注解检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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