在iPhone上的MKMapView中移动注释时避免闪烁

时间:2010-08-18 16:32:39

标签: iphone mkmapview

据我所知,没有办法移动注释而不删除&将它重新添加到MapView(也许我错了)。

有没有办法阻止在删除&之间重新绘制MapView。重新添加注释?现在,删除注释后重新绘制会导致没有注释的帧,因此它似乎闪烁。

我需要一个适用于iOS 3.1更新的解决方案。

由于

3 个答案:

答案 0 :(得分:11)

在iOS4中

[theAnnotation setCoordinate:newCoordinate];

答案 1 :(得分:5)

我想出了如何使用以下代码实现无闪烁注释“更新”。在坚果壳中,您将新的引脚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];
}

然后,我打电话来搜索和删除任何退役的引脚:

- (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;

}

最后,在后台摆脱旧针:

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

答案 2 :(得分:1)

3.1你必须破解。我会看到两种可能性,要么试图通过潜伏在头文件中来强制更改当前注释的坐标并直接访问内存,要么摆弄UIWindow和图形上下文以试图避免在下一个runloop周期中完成绘图实际上到达了屏幕。

编辑:第三种替代方案,可能是最简单的方法,就是在MapKit之外进行自己的轻量级注释实现。