注释没有按照我提供的顺序掉落在地图视图上

发布于 2024-12-25 13:07:59 字数 643 浏览 0 评论 0原文

我开发了一个应用程序,它使用地图视图,该视图在同一位置有多个注释,但它不会删除我提供注释顺序的引脚。我从数组中添加了注释,但它没有显示相同的顺序。我需要第一个对象 [注释] 位于该位置的顶部。当用户点击注释时,它应该将第一个对象显示为标注。任何建议做同样的事情。

谢谢 我已经尝试过这种方法,但没有运气..

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {


for (MKAnnotationView *view in views) {

    if ([[view annotation] isKindOfClass:[Annotation class]]) {
        Annotation *customAnnotation = (Annotation*) [view annotation];
        if ([customAnnotation markerID]==0)
             [[view superview] bringSubviewToFront:view];
        else {
            [[view superview] sendSubviewToBack:view];
        }
    }
}
}

I developed an application, which uses the map view, which has multiple annotations at the same location, but it is not dropping the pins which I provided the order for the annotations. I added annotations from the array, but it is not showing the same order. I need the first object [annotation] to be the top on the location. when user taps on the annotation, it should show the first object as callout. Any suggestions to do the same.

Thanks
I have already tried this approach, but no luck..

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {


for (MKAnnotationView *view in views) {

    if ([[view annotation] isKindOfClass:[Annotation class]]) {
        Annotation *customAnnotation = (Annotation*) [view annotation];
        if ([customAnnotation markerID]==0)
             [[view superview] bringSubviewToFront:view];
        else {
            [[view superview] sendSubviewToBack:view];
        }
    }
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神经大条 2025-01-01 13:07:59

注释可以按任意顺序添加,并且可以像表视图中的单元格一样在视图中添加或删除。因此 z 层可能会以您可能不希望的方式变化。

这是一些可能对您有帮助的示例代码。我有一张显示搜索结果图钉的地图。它们分为正常结果和收藏夹。我希望收藏夹始终位于顶部或其他图钉上。我还有一个“矩形”来突出显示选定的地图图钉,我总是希望它位于所有注释的顶部。我使用此代码将不同类型的注释放入正确的 z 层顺序中:

- (void) mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views {

    MKAnnotationView *theReticleView = nil;

    for (MKAnnotationView *view in views) {
        if ([[view annotation] isKindOfClass:[SearchResult class]]) {
            SearchResult *result = (SearchResult*) [view annotation];
            if ([result.isFavorite boolValue])  {
                [[view superview] bringSubviewToFront:view];
            } else {
                [[view superview] sendSubviewToBack:view];
            }
        }
        else if ([[view annotation] isKindOfClass:[MapReticle class]]) {
            theReticleView = view;
        }
    }
    if (theReticleView != nil)
        [[theReticleView superview] bringSubviewToFront:theReticleView];

}

Annotations can put added in an arbitrary order, and can be added or removed from the view the same way cells are in a table view. So the z-layer can vary in a way you might not want.

Here is some sample code that might help you. I have a map that displays pins for search results. They are divided into normal results and favorites. I want the favorites to always be on top or the other pins. I also have a "recticle" to highlight a selected map pin, and I always want this to be on top of all of the annotations. I use this code to get different types of annotations into the right z-layer order:

- (void) mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views {

    MKAnnotationView *theReticleView = nil;

    for (MKAnnotationView *view in views) {
        if ([[view annotation] isKindOfClass:[SearchResult class]]) {
            SearchResult *result = (SearchResult*) [view annotation];
            if ([result.isFavorite boolValue])  {
                [[view superview] bringSubviewToFront:view];
            } else {
                [[view superview] sendSubviewToBack:view];
            }
        }
        else if ([[view annotation] isKindOfClass:[MapReticle class]]) {
            theReticleView = view;
        }
    }
    if (theReticleView != nil)
        [[theReticleView superview] bringSubviewToFront:theReticleView];

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文