gpt4 book ai didi

objective-c - 在不闪烁的情况下更新 MKannotation 图像

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:05:05 25 4
gpt4 key购买 nike

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

我尝试了以下方法:

//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];
}

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

有人有什么想法吗?

最佳答案

在注解不为 nil 的情况下,不是添加和删除,而是尝试这个:

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

关于objective-c - 在不闪烁的情况下更新 MKannotation 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6375473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com