2017-07-21 12 views
0

タップしたときにMKAnnotationViewの上に完全なカスタム吹き出しビューを表示したいとします。私はいくつかの答えを見つけたが、それらのどれも働いていないと私はそれが行われることがわかっているので、いくつかのアプリでそれを見てきました。また、吹き出しにいくつかのボタンを表示し、それらをタップすると異なるアクションを実行したいと思います。私はObjective-Cに取り組んでおり、本当に助けに感謝します。MKAnnotationViewのカスタム吹き出し

答えて

0

あなたはviewForAnnotation方法でカスタムコードを入れて、あなたの要件ごとにビューを更新する必要があります。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
    { 
     return nil; 
    } 
    else if ([annotation isKindOfClass:[YOUR_CUSOM_ANNO_CLASS_NAME class]]) // use whatever annotation class you used when creating the annotation 
    { 
     static NSString * const identifier = @"customAnno"; 

     MKAnnotationView* annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 

     if (annotationView) 
     { 
      annotationView.annotation = annotation; 
     } 
     else 
     { 
      annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation 
                  reuseIdentifier:identifier]; 
     } 

     annotationView.canShowCallout = YES; 
     annotationView.image = [UIImage imageNamed:]; 

     return annotationView; 
    } 
    return nil; 
} 

素晴らしいdemoはgithubの上sghiassyであります。注釈を理解するのに役立ちます。

0

iOS 9以降、MKAnnotationViewのdetailCalloutAccessoryViewプロパティを使用できます。任意のビューに設定できます。チュートリアルでiOS 9の第14章でこれについてのRay Wenderlichのチュートリアルがあります。

関連する問題