MKAnnotation - 地图标注气泡弹出在其他地图标注后面

7

我的地图标记可能会很密集,因此当选择一个标记时,弹出框会弹出,但大多数情况下会被所有其他地图标记遮盖 - 如果有一个代表选定地图标记(而不是点击弹出框)的委托,我可以将Map Pin带到最前面。

有什么解决方法吗?

2个回答

2
如果您正在使用自定义注释视图,可以添加一个观察者来监视所选属性,这将像委托一样在选择大头针时起作用。
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
    MKAnnotation *annview = ...code to either dequeue or create new object...
    [annview addObserver:self forKeyPath:@"selected" options:NSKeyValueObservingOptionNew context:@"selectedmapannotation"];               
    return annview;
}

然后,您可以使用所选状态进行监视。
- (void)observeValueForKeyPath:(NSString *)keyPath
                  ofObject:(id)object
                    change:(NSDictionary *)change
                   context:(void *)context;

Mugunth Kumar提供的答案也能给你想要的结果,只是你在问题中提到了类似委托的功能。

编辑:

下面是observeValueForKeyPath:ofObject:change:context:方法的示例内容:

NSString *action = (NSString*)context;

if([action isEqualToString:@"selectedmapannotation"]){
    BOOL annotationAppeared = [[change valueForKey:@"new"] boolValue];
    MKAnnotationView *ann = (MKAnnotationView *)object;

    if (annotationAppeared) {
        // do something with the annotation when it is selected
    }
    else {
        // do something with the annotation when it is de-selected
    }
}

你能详细说明一下吗?observeValueForKeyPath的实现会是什么样子?你能举个例子吗? - si28719e
编辑了答案并添加了一个示例实现,希望有所帮助! - acqu13sce

1

UICallout视图是MKAnnotationView的子视图。因此,我认为如果您将地图ping带到前面,UICAlloutView也会在那里。


你如何通过编程将UICalloutView置于最前面? - si28719e

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接