gpt4 book ai didi

iphone - 点击覆盖时显示标注

转载 作者:太空狗 更新时间:2023-10-30 04:01:27 26 4
gpt4 key购买 nike

我有一个带有多个叠加层的 MKMapView。一切正常,而且工作起来如此简单令人难以置信。但是,有一件事我无法开始工作。这个想法很简单:当用户在覆盖层覆盖的区域内点击时,必须出现包含有关该覆盖层的一些信息的标注。叠加层都是 MKPolygon,它们遵循 MKOverlay 协议(protocol),因此也遵循 MKAnnotation 协议(protocol)。

The MKOverlay protocol conforms to the MKAnnotation protocol. As a result, all overlay objects are also annotation objects and can be treated as one or both in your code. If you opt to treat an overlay object as both, you are responsible for managing that object in two places. If you want to display both an overlay view and annotation view for it, you must implement both the mapView:viewForOverlay: and mapView:viewForAnnotation: methods in your application delegate. It also means that you must add and remove the object from both the overlays and annotations arrays of your map.

这来自 Apple 文档。我试过这样的事情:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

MKAnnotationView *aView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
aView.canShowCallout = YES;
}

但这似乎行不通。我试过使用手势识别器,但除了使用 canShowCallOut 属性之外,我不知道如何显示标注...

最佳答案

我想您还必须添加 MKOverlays 作为注释

 [self.mapView addAnnotations:myOverlays];

然后在 (mapView:viewForAnnotation) 中返回一个未隐藏的 MKAnnotationView,图形(可点击)或零 alpha View 。接下来,为每个 MKOverlayView 添加一个 UITapGestureRecognizer,确保它与 map 的手势一起工作(用于同时识别的 UIGestureRecognizerDelegate 实现)。最后,当你的手势识别器触发时,这样做

[self.mapView setSelectedAnnotations:[NSArray arrayWithObject:myOverlayView.overlay]];

不过,我不确定这是否真的触发了 callOut 显示。还要确保从覆盖对象返回标题和/或副标题。

关于iphone - 点击覆盖时显示标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6274743/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com