【问题标题】:MKAnnotation - Map Pin callout pops up behind other map pinsMKAnnotation - 地图图钉标注弹出在其他地图图钉后面
【发布时间】:2009-09-22 04:04:40
【问题描述】:

My map pins can be quite densely populated so that when a pin is selected the callout pops up but is mostly obscured by all the other map pins - I can bring the Map Pin to the front it there were a delegate for selected map大头针(未点击标注,已选择大头针)。

对解决方法有什么建议吗?

【问题讨论】:

    标签: iphone


    【解决方案1】:

    如果您使用自定义注释视图,您可以为选定的属性添加一个观察者,该观察者在选择引脚时充当代理。

    - (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 实现实际上是什么样子的?能举个例子吗?
    • 编辑了答案以添加示例实现,希望对您有所帮助!
    【解决方案2】:

    UICallout 视图是 MKAnnotationView 的子视图。所以,我想如果你把 Map ping 放在前面,UICalloutView 也会在那里。

    【讨论】:

    • 如何以编程方式将 UICalloutView 置于最前面?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-30
    • 1970-01-01
    相关资源
    最近更新 更多