Rod*_*257 2 objective-c mapkit ios
我想每5秒在mapview上更新一些注释的图像,但是我不想删除它们并将它们重新添加到地图中,因为这会导致它们"闪烁"或刷新,(即消失然后重新出现) .我希望它是无缝的.
我尝试过以下方法:
//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];
}
Run Code Online (Sandbox Code Playgroud)
作为一个想法,如果我在顶部添加新图标,我可以删除旧图标,但这仍然导致闪烁.
有没有人有任何想法?
小智 8
如果注释不是nil,而不是添加和删除,请尝试以下操作:
annotation.customImage = ... //the new image
MKAnnotationView *av = [self.mapView viewForAnnotation:annotation];
av.image = annotation.customImage;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3827 次 |
| 最近记录: |