据我所知,没有办法移动注释而不删除并重新添加到MapView(也许我错了).
有没有办法阻止在删除和重新添加注释之间重新绘制MapView?现在,删除注释后重新绘制会导致没有注释的帧,因此它似乎闪烁.
我需要一个适用于iOS 3.1更新的解决方案.
谢谢
eli*_*ego 12
在iOS4中
[theAnnotation setCoordinate:newCoordinate];
Run Code Online (Sandbox Code Playgroud)
我想出了如何使用下面的代码实现无闪烁注释"更新".在坚果壳中,您将新的引脚FIRST添加,然后删除旧的引脚.我还没有简化我的代码,但你会明白这个想法.
-(void)replacePin:(NSString *)title SubTitle:(NSString *)subTitle Location:(CLLocationCoordinate2D)location PinType:(MapAnnotationType)pinType Loading:(BOOL)loading Progress:(float)progress
{
//Find and "decommission" the old pin... (basically flags it for deletion later)
for (MyMapAnnotation *annotation in map.annotations)
{
if (![annotation isKindOfClass:[MKUserLocation class]])
{
if ([annotation.title isEqualToString:title])
annotation.decommissioned = YES;
}
}
//add the new pin...
MyMapAnnotation *stationPin = nil;
stationPin = [[MyMapAnnotation alloc] initWithCoordinate:Location
annotationType:pinType
title:title
subtitle:subTitle
loading:loading
decommissioned:NO
progress:progress];
[map addAnnotation:stationPin];
[stationPin release];
}
Run Code Online (Sandbox Code Playgroud)
然后,我打电话来搜索并删除任何退役的引脚:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView* annotationView = nil;
if (![annotation isKindOfClass:[MKUserLocation class]])
{
MyMapAnnotation* annotation = (MyMapAnnotation*)annotation;
//your own details...
//delete any decommissioned pins...
[self performSelectorOnMainThread:@selector(deletePin:) withObject:annotation.title waitUntilDone:NO];
}
return annotationView;
}
Run Code Online (Sandbox Code Playgroud)
最后,在后台摆脱旧针:
-(void)deletePin:(NSString *)stationCode
{
for (MyMapAnnotation *annotation in map.annotations)
{
if (![annotation isKindOfClass:[MKUserLocation class]])
{
if ([annotation.title isEqualToString:stationCode])
{
if (annotation.decommissioned)
[map removeAnnotation:annotation];
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4781 次 |
| 最近记录: |