【问题标题】:How to add scrollview as an info window google map ios如何将滚动视图添加为信息窗口谷歌地图 ios
【发布时间】:2014-06-14 01:12:42
【问题描述】:

我的客户需要在集成在我的应用程序中的谷歌地图的信息窗口中添加更多信息。所以我决定使用滚动视图作为信息窗口。我正在使用方法 - (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker 在地图顶部表示我的滚动视图。

这是我的代码:

- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker {


       self.propertyNameLabel.text = marker.title;

       self.addressLabel.text = marker.snippet;


      [self.scrollViewTest setContentSize:CGSizeMake(600.00, 610.00)];

      [self.searchMap addSubview:self.scrollViewTest];


      UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleMoreTap)];
     tapGestureRecognizer.numberOfTapsRequired = 1;
    [self.moreLabel addGestureRecognizer:tapGestureRecognizer];
    self.moreLabel.userInteractionEnabled = YES;
    [tapGestureRecognizer release];


    return YES;

}

当我单击标记时,会显示滚动视图,但滚动不起作用。我已经设置了内容大小,但仍然无法正常工作。请帮帮我,

谢谢。

【问题讨论】:

    标签: ios google-maps uiscrollview google-maps-sdk-ios


    【解决方案1】:

    markerInfoWindow 委托方法返回的视图不允许交互。谷歌地图似乎只是拍摄视图的快照并将其添加为图像,因此按钮、滚动视图等不起作用。

    解决方案是在 didTapInfoWindowOfMarker 中创建一个单独的视图并将其作为子视图添加到您的主视图(也包含 mapView 的那个)。当然,这确实会产生其他复杂性,因为它与 mapView 没有任何关联,因此您需要自行管理关闭它等。

    【讨论】:

    • 我同意,最好创建和管理一个完全独立的子视图。 See my answer here 使用 SMCalloutView(而不是滚动视图)的示例。
    【解决方案2】:

    您使用了错误的委托方法来编辑信息表。

    这行代码 [self.searchMap addSubview:self.scrollViewTest]; 将子视图添加到您的地图中,而不是信息窗口中。

    你应该使用这个委托方法:-

    -(UIView*)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker{
      //TODO: Custom your view here
      UIView * view =[[UIView alloc]init];
      return  view;
    }
    
    - (void)mapView:(GMSMapView *)mapView 
         didTapInfoWindowOfMarker:(GMSMarker *)marker{
    
     //TODO: Some logic to set the model that will be using after notification is posted
       [[NSNotificationCenter defaultCenter] postNotificationName:@"triggerActionLikeAButton" object:nil];
     }
    

    【讨论】:

    • 之前,我使用了委托方法 -(UIView*)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker。但是信息窗口中的按钮没有响应。这就是为什么我使用另一种方法并将新的自定义视图作为子视图添加到地图视图。
    • 关于 infoWindow 内的按钮没有响应是正确的。我之前也遇到过类似的问题,尝试了很多不同的方法,但仍然无法解决。最后,我不得不使用 NSNotification 来解决 infoWindow Tap 问题。我添加了上面的代码。
    猜你喜欢
    • 2011-11-09
    • 2018-06-05
    • 2013-08-22
    • 2013-03-01
    • 1970-01-01
    • 2015-04-09
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多