在iPhone上的MKMapView中移动注释时避免闪烁 [英] Avoid flicker when moving annotations in a MKMapView on iPhone
问题描述
据我所知,没有办法移动注释而不删除&将它重新添加到MapView(也许我错了)。
有没有办法阻止MapView在删除&之间重新绘制重新添加注释?现在,删除注释后重新绘制会导致没有注释的帧,因此它似乎闪烁。
我需要一个适用于iOS 3.1更新的解决方案。 / p>
谢谢
我想出了如何实现无闪烁注释更新使用以下代码。在坚果壳中,您将新的引脚添加为FIRST,然后删除旧的引脚。我还没有精简我的代码,但你会明白这一点。
- (void)replacePin:(NSString *) title SubTitle:(NSString *)subTitle Location:(CLLocationCoordinate2D)location PinType:(MapAnnotationType)pinType Loading:(BOOL)loading进度:(float)进度
{
//查找并退役旧的pin ...(基本上将其标记为以后删除)
for(MyMapAnnotation *注释在map.annotations中)
{
if(![annotation isKindOfClass:[MKUserLocation class]])
{
if([annotation.title isEqualToString:title])
annotation.decommissioned = YES;
}
}
//添加新引脚...
MyMapAnnotation * stationPin = nil;
stationPin = [[MyMapAnnotation alloc] initWithCoordinate:Location
annotationType:pinType
title:title
subtitle:subTitle
loading:loading
decommissioned:NO
进展:进展];
[map addAnnotation:stationPin];
[stationPin release];
}
然后我打电话来搜索并删除任何退役的引脚:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id< MKAnnotation>)注释
{
MKAnnotationView * annotationView = nil;
if(![annotation isKindOfClass:[MKUserLocation class]])
{
MyMapAnnotation * annotation =(MyMapAnnotation *)annotation;
//你自己的详细信息...
//删除任何退役的引脚...
[self performSelectorOnMainThread:@selector(deletePin :) withObject:annotation .title waitUntilDone:NO];
}
返回annotationView;
}
最后,在后台摆脱旧针:
- (void)deletePin:(NSString *)stationCode
{
for(MyMapAnnotation * annotation)在map.annotations中)
{
if(![annotation isKindOfClass:[MKUserLocation class]])
{
if([annotation.title isEqualToString:stationCode])
{
if(annotation.decommissioned)
[map removeAnnotation:annotation];
}
}
}
}
As far as I know, there isn't a way to move an annotation without removing & re-adding it to the MapView (Maybe I'm wrong).
Is there a way to prevent the MapView from being re-drawn between removing & re-adding the annotation? Right now the re-draw after removing the annotation causes a frame without the annotation, so it appears to flicker.
I need a solution that works in iOS 3.1 updates.
Thanks
I figured out how achieve flicker free annotation "updates" using the below code. In a nut shell, you add your new pin FIRST, then delete the old one AFTER. I haven't streamlined my code yet but you'll get the idea.
-(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];
}
Then AFTER, I make the call to search for and remove any decommissioned pins:
- (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;
}
And finally, in the background get rid of the old pin:
-(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];
}
}
}
}
这篇关于在iPhone上的MKMapView中移动注释时避免闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!