【问题标题】:How to add Action selector to the popup bubble on Annotation view [duplicate]如何将动作选择器添加到注释视图的弹出气泡中[重复]
【发布时间】:2013-08-19 06:57:13
【问题描述】:

我对 MapKit 实现非常陌生

在我的应用中,一页是地图视图

我已经展示了大量的 pin 及其注释操作。

我在 popup bubble 上添加了一个 Discloser 按钮,并为这些 Discloser 按钮设置操作,如下所示。

i Want to Same action When tap on that gray bubble

//To add a discloser button to show route map
        UIButton *detailBtn=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.rightCalloutAccessoryView=detailBtn;
        [detailBtn addTarget:self action:@selector(showRoute:) forControlEvents:UIControlEventTouchUpInside];
        DisplayMap *ann=(DisplayMap *)annotation;
        detailBtn.tag = ann.detailButtonTag;



//viewForAnnotation DELEGATE for annotions
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {
    MKPinAnnotationView *pinView = nil;
    if(annotation != mapView.userLocation)
    {
        static NSString *defaultPinID = @"com.invasivecode.pin";
        pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinView == nil ) pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] ;
        pinView.pinColor = MKPinAnnotationColorRed;
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;

        //To add a discloser button to show route map
        UIButton *detailBtn=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.rightCalloutAccessoryView=detailBtn;
        [detailBtn addTarget:self action:@selector(showRoute:) forControlEvents:UIControlEventTouchUpInside];
        DisplayMap *ann=(DisplayMap *)annotation;
        detailBtn.tag = ann.detailButtonTag;
    }
    else
    {
        [mapView.userLocation setTitle:@"I am here"];
    }
    return pinView;
}

但我想在点击那个灰色气泡时采取同样的行动..

怎么做

【问题讨论】:

    标签: iphone objective-c annotations mkmapview mapkit


    【解决方案1】:

    您必须使用以下委托方法来点击气泡。

        -(void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(id<GMSMarker>)marker 
       {
        DetailViewController *Detail = [[DetailViewController alloc]initWithNibName:@" DetailViewController" bundle:nil];    
        Detail.data=marker.userData;  // passing the data    
        [self.navigationController pushViewController:restDetail animated:YES];  
       }
    

    【讨论】:

      【解决方案2】:

      MKMapViewDelegate 有两种方法:

      - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
      - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
      

      有关如何使用这些方法的更多详细信息,您可以查看 Rob 的Answer

      更新:

      为此,您可以使用Custom Callout。您可以使用“showRoute”方法创建自定义按钮,并将其作为子视图添加到自定义标注内容视图。

      【讨论】:

      • 这些方法可以点击 pin 但我需要一个动作来点击弹出气泡
      • @user2492409 :检查我的答案中的更新
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-03
      相关资源
      最近更新 更多