ios – 在MKMapView中选择第二个注释时检测

ios – 在MKMapView中选择第二个注释时检测,第1张

概述当用户在地图中选择注释时,我会显示带有信息的底部视图,例如google地图应用. 我在地图的代表中显示它: - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view 当用户取消选择它(通过在地图上的任何位置录制)时,我隐藏了我的底部视图.这是在相反的委托方法中完成的: - (void) 当用户在地图中选择注释时,我会显示带有信息的底部视图,例如Google地图应用.
我在地图的代表中显示它:
- (voID)mapVIEw:(MKMapVIEw *)mapVIEw dIDSelectAnnotationVIEw:(MKAnnotationVIEw *)vIEw

当用户取消选择它(通过在地图上的任何位置录制)时,我隐藏了我的底部视图.这是在相反的委托方法中完成的:

- (voID)mapVIEw:(MKMapVIEw *)mapVIEw dIDdeselectAnnotationVIEw:(MKAnnotationVIEw *)vIEw

它运作良好,我很高兴.但是,如果用户选择第二个注释(即:他点击第一个注释,然后点击另一个注释,同时不首先取消选择注释),我不想隐藏我的底部视图然后再次显示它.我只想改变它的信息.

但是,由于mapVIEw:dIDdeselectAnnotationVIEw:在mapVIEw:dIDSelectAnnotationVIEw:之前调用,我无法弄清楚如何检测我上面描述的情况.

我的问题是:如何检测用户选择第二个注释或者,我该如何以其他方式解决此问题?

解决方法 也许尝试在dIDdeselectAnnotationVIEw方法中加一个延迟来隐藏你的bottomVIEw.您需要存储对上次选择的注释视图的引用.

例:

@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;    }}
总结

以上是内存溢出为你收集整理的ios – 在MKMapView中选择第二个注释时检测全部内容,希望文章能够帮你解决ios – 在MKMapView中选择第二个注释时检测所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1107690.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存