【发布时间】:2012-11-24 22:12:24
【问题描述】:
在 iOS6 中,我正在尝试为注释创建自定义标注,其中包含图像、标题、描述等详细信息。我在这里看到了相关帖子,但不是我想要的。在我的应用程序中,当您选择注释时,您可以选择 4 个按钮。现在我正在尝试为第 4 个按钮创建选项,这是详细的标注。
我创建了一个代表自定义标注的 UIView 类。
编辑:
在 Live2Enjoy7 的帮助下,我修改了我的代码,如下所示。
BuildingViewController.m
- (void)MapMenu:(MapMenu *)menu didSelectButton:(NSInteger)index{
if (index == 3) {
image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
_buildingShowCallout = YES;
[parentView removeAnnotation:self];
[parentView addAnnotation:self];
}
}
如果用户按下按钮,此方法,创建新图像(使用 url 链接),设置 _buildingShowCallout = YES,最后删除并再次添加选定的注释以使 viewForAnnotation 方法起作用。
在我的 MapViewController.m 中
- (MKAnnotationView *)mapView:(MKMapView *)_mapView viewForAnnotation:(id<MKAnnotation>)annotation{
if ([annotation isKindOfClass:[MKUserLocation class]]) {
return nil;
}
static NSString *identifier = @"MyAnnotation";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
BuildingViewController* building = (BuildingViewController*) annotation;
// If a new annotation is created
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:building reuseIdentifier:identifier];
if (building.buildingShowCallout) {// Create the custom callout
BuildingCallOut* buildingCallout = [[BuildingCallOut alloc]initWithFrame:CGRectMake(0, 0, 200, 150)];
[buildingCallout showCallout:building];
[annotationView addSubview:buildingCallout];//add the new callout as subview of the selected annotation.
}
} else{
annotationView.annotation = annotation;
if (building.buildingShowCallout) {// Create the custom callout
BuildingCallOut* buildingCallout = [[BuildingCallOut alloc]initWithFrame:CGRectMake(0, 0, 200, 150)];
[buildingCallout showCallout:building];
[annotationView addSubview:buildingCallout];//add the new callout as subview of the selected annotation.
}
}
return annotationView;
}
这很好,但现在我遇到了一个新问题。
- 如果您选择查看一个注释的标注,然后选择查看另一个注释的标注,则前一个注释会保留在地图上。我该如何解决?
截图 ![在此处输入图片说明][1]
如您所见.. 当我在底部调用新的标注时,屏幕顶部的前一个标注仍然存在。努力寻找将“消失”线放在哪里。 提前致谢
【问题讨论】:
标签: ios xcode uiview annotations