更新MKannotation图像而不闪烁 [英] Updating MKannotation image without flashing

查看:89
本文介绍了更新MKannotation图像而不闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每5秒在mapview上更新一些注释的图像,但是我不想删除它们并将它们重新添加到地图中,因为这会导致它们闪烁或刷新,(即消失然后重新出现)。我希望它是无缝的。

I want to update the images of some of my annotations on a mapview every 5 seconds, however I dont' want to remove and re-add them to the map as this causes them to 'flash' or refresh, (ie disapear then reappear). I want it to be seamless.

我尝试了以下内容:

//get the current icon
        UserAnnotation *annotation = [self GetUserIconWithDeviceId:deviceId];

        //make a new annotation for it 
        UserAnnotation *newAnnotation = [[UserAnnotation alloc]
                                         initWithCoordinate: userCoordinates
                                         addressDictionary:nil];
        newAnnotation.title = name;
        newAnnotation.userDeviceId = deviceId;
        NSInteger ageIndicator = [[userLocation objectForKey: @"ageIndicator"] integerValue];
        newAnnotation.customImage = [UserIconHelpers imageWithAgeBorder:ageIndicator FromImage: userImage];



        //if its not there, add it 
        if (annotation != nil){
            //move it 

            //update location
            annotation.coordinate = userCoordinates;

            //add new one 
            [self.mapView addAnnotation: newAnnotation];

            //delete old one 
            [self.mapView removeAnnotation: annotation];

        } else {
        //just addd the new one 
            [self.mapView addAnnotation: newAnnotation]; 
        }

如果我在顶部添加了新图标我可以删除旧的图标,但这仍然导致闪烁。

as a thought that if I added the new icon on top I could then remove the old icon, but this still caused the flashing.

有没有人有任何想法?

Has anyone got any ideas?

推荐答案

如果注释不是nil,而不是添加和删除,请尝试:

In the case where the annotation is not nil, instead of adding and removing, try this:

annotation.customImage = ... //the new image
MKAnnotationView *av = [self.mapView viewForAnnotation:annotation];
av.image = annotation.customImage;

这篇关于更新MKannotation图像而不闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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