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つの新しい問題を抱えています。
- ある注釈のコールアウトを表示することを選択してから、別の注釈のコールアウトを表示することを選択した場合、前の注釈はマップ上に残ります。どうすればこれを解決できますか?
スクリーンショット![ここに画像の説明を入力してください] [1]
ご覧のとおり、画面の上部にある以前のコールアウトは、下部にある新しいコールアウトを呼び出しているときに残ります。「消える」線をどこに置くかを見つけるのに苦労しています。前もって感謝します