替换 mkannotationview 中的 calloutaccessoryview

发布于 2024-08-27 20:57:31 字数 567 浏览 4 评论 0原文

在我的 viewForAnnotation 委托中,我创建了一个 MKAnnotationView,其中 leftCalloutaccessory 作为信息按钮。当点击信息按钮时,我想用 UIActivityIndi​​cator 替换它。所以在 calloutAccessoryTapped 委托中,我写了 view.leftCalloutaccessoryView = [UIActivityIndi​​cator IndicatorWithStyle:UIActivityIndi​​catorWhite];

标注附件似乎发生了变化,但视图似乎没有立即更新。

当标注配件被隐藏(通过点击另一个引脚)并重新打开时,我看到一个旋转器。但除此之外,我不这样做。

我也尝试调用 [view setNeedsdisplay][view setNeedsLayout][view layoutsubviews] 但徒劳。

有什么建议/指示吗?

In my viewForAnnotation delegate, I create a MKAnnotationView with leftCalloutaccessory as a info button. When the info button is tapped, I want to replace it with a UIActivityIndicator. So in the calloutAccessoryTapped delegate, I wrote
view.leftCalloutaccessoryView = [UIActivityIndicator indicatorWithStyle:UIActivityIndicatorWhite];

The callout accessory seems to change, but it seems like the view doesn't get updated immediately.

That's when the callout accessory gets hidden (by tapping another pin) and is re-opened, I see a spinner. But otherwise, I don't.

I tried calling [view setNeedsdisplay] and [view setNeedsLayout] and [view layoutsubviews] as well but in vain.

Any suggestions/pointers?

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

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

发布评论

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

评论(2

橘香 2024-09-03 20:57:31

我会考虑删除并重新添加您的注释。这看起来有点笨重,但可能有用。

I would consider removing and re-adding your annotation. It seems a little heavy handed, but might work.

无敌元气妹 2024-09-03 20:57:31

我遇到了类似的问题 - 如果有与注释关联的图像,我需要为 leftCalloutAccessoryView 显示一张图像。尝试在mapView:didSelectAnnotationView而不是mapView:viewForAnnotation中设置它

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)annotView
{
    ...

    if(imgURL.length>1){            
        // set a thread that will load the image 
        // but don't set the leftCalloutAccessoryView until the image is loaded 
        dispatch_queue_t downloader = dispatch_queue_create("annotation image downloader",NULL);
        dispatch_async(downloader, ^{
            NSURL* photoURL = [NSURL URLWithString:imgURL];
            NSData* photoData = [NSData dataWithContentsOfURL:photoURL];
            UIImage* photoImage = [UIImage imageWithData:photoData];
            dispatch_async(dispatch_get_main_queue(), ^{
                annotView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
                [(UIImageView *) annotView.leftCalloutAccessoryView setImage:photoImage];
            });                
        });
    }
}

I was having a similar problem -- I needed to display an image for the leftCalloutAccessoryView if there was one associated with the annotation. Try setting it in mapView:didSelectAnnotationView instead of in mapView:viewForAnnotation

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)annotView
{
    ...

    if(imgURL.length>1){            
        // set a thread that will load the image 
        // but don't set the leftCalloutAccessoryView until the image is loaded 
        dispatch_queue_t downloader = dispatch_queue_create("annotation image downloader",NULL);
        dispatch_async(downloader, ^{
            NSURL* photoURL = [NSURL URLWithString:imgURL];
            NSData* photoData = [NSData dataWithContentsOfURL:photoURL];
            UIImage* photoImage = [UIImage imageWithData:photoData];
            dispatch_async(dispatch_get_main_queue(), ^{
                annotView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)];
                [(UIImageView *) annotView.leftCalloutAccessoryView setImage:photoImage];
            });                
        });
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文