更新 MKAnnotationView 中的图像

发布于 2024-11-30 10:05:04 字数 935 浏览 1 评论 0原文

我正在编写一个应用程序,在 leftCalloutAccessoryView 中显示来自服务器的缩略图。在实际获取图像之前,我会显示一个地标图像。下载照片后,将调用一个方法,我想更新该图像而不删除原始注释并放置另一个注释。我只是希望图像从占位符切换到下载的缩略图。下面是不起作用的代码,但如果有人能让我知道我是否走在正确的轨道上,那就太好了。

MyAnnotationClass *annotation=[[MyAnnotationClass alloc] initWithCoordinate:item.location];
[annotation setItem:item];
if(item.title){
    annotation.name=item.title;
}
else{
    annotation.name=@"no title";
}
[annotation setDescription:[[NSString alloc] initWithFormat:@"Views:%d Likes:%d Comments:%d",item.views,item.likes,item.comments]];
[annotation setImage:[[photo.thumb copyWithDimensions: CGSizeMake(32.0, 32.0)] autorelease]];

MKAnnotationView *av=[__mapView viewForAnnotation:annotation];
UIImageView *imageView=[[UIImageView alloc] initWithImage:annotation.image];
imageView.frame=CGRectMake(0.0, 0.0, 32.0, 32.0);
av.leftCalloutAccessoryView=imageView;
[annotation release];

我已经在这里寻找了一段时间,但我找不到任何可以满足我需要的东西。谢谢

I am writing an application that displays a thumbnail from a server in the leftCalloutAccessoryView. Before I actually get the image, I display a placemark image. Once the photo is downloaded, a method is called and I want to update that image without removing the original annotation and placing another. I just wan the image to switch from the placeholder to the downloaded thumbnail. Below is the code that does not work, but if someone could let me know if I'm on the right track, that would be great.

MyAnnotationClass *annotation=[[MyAnnotationClass alloc] initWithCoordinate:item.location];
[annotation setItem:item];
if(item.title){
    annotation.name=item.title;
}
else{
    annotation.name=@"no title";
}
[annotation setDescription:[[NSString alloc] initWithFormat:@"Views:%d Likes:%d Comments:%d",item.views,item.likes,item.comments]];
[annotation setImage:[[photo.thumb copyWithDimensions: CGSizeMake(32.0, 32.0)] autorelease]];

MKAnnotationView *av=[__mapView viewForAnnotation:annotation];
UIImageView *imageView=[[UIImageView alloc] initWithImage:annotation.image];
imageView.frame=CGRectMake(0.0, 0.0, 32.0, 32.0);
av.leftCalloutAccessoryView=imageView;
[annotation release];

I have been looking around here for quite sometime, but nothing that I can find will do what I need. Thanks

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

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

发布评论

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

评论(1

我做我的改变 2024-12-07 10:05:04

如果注释已在地图上并且您想要更新它,请勿创建新注释。

相反,在地图视图的 annotations 数组中找到要更新的注释并更新其属性。然后对该现有注释调用 viewForAnnotation: 并更新 leftCalloutAccessoryView

另外,请确保 viewForAnnotation delegate 方法具有通过检查注释的属性将 leftCalloutAccessoryView 设置为占位符图像或实际图像的逻辑 (并且并不总是占位符图像)。

这个其他问题有一些示例代码可能会有所帮助。

If the annotation is already on the map and you want to update it, don't create a new one.

Instead, find the annotation you want to update in the map view's annotations array and update its properties. Then call viewForAnnotation: on that existing annotation and update the leftCalloutAccessoryView.

Also, make sure the viewForAnnotation delegate method has logic that sets the leftCalloutAccessoryView to either the placeholder image or the actual image by checking the annotation's properties (and not always the placeholder image).

This other question has some sample code that may help.

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