如何在InfoWindow中包含一个button

我跟随本教程如何添加自定义信息窗口谷歌地图标记,在UIView我已经添加了一个button,并创build了一个IBAction,但是当我点击它没有发生

我的infoWindow视图代码看起来像这样

。H

#import <UIKit/UIKit.h> #import "Details.h" @interface MarkerInfoWindowView : UIView @property (weak, nonatomic) IBOutlet UIImageView *imageView; @property (weak, nonatomic) IBOutlet UILabel *label1; @property (weak, nonatomic) IBOutlet UILabel *label2; @property (weak, nonatomic) IBOutlet UIButton *btn1; - (void) initializeWithDetails:(Details*)p_details; @end 

.M

 #import "MarkerInfoWindowView.h" @implementation MarkerInfoWindowView - (void) initializeWithDetails:(Details*)p_details { if(self != nil) { self.imageView.image = [UIImage imageWithContentsOfFile:p_basicDetails.imageURL]; self.label1.text = p_details.l1; self.label2.text = p_details.l2; } } -(IBAction) btn1_Clicked:(id)sender { NSLog(@"button clicked"); } @end 

然后在我的视图控制器的主屏幕和地图

 -(MarkerInfoWindowView*) customInfoWindow { if(_customInfoWindow == nil) { _customInfoWindow = [[[NSBundle mainBundle] loadNibNamed:@"MarkerInfoWindowView" owner:self options:nil] objectAtIndex:0]; } return _customInfoWindow; } - (UIView *)mapView:(GMSMapView *)p_mapView markerInfoWindow:(GMSMarker *)p_marker { Details* temp = [[Details alloc] init]; temp.l1 = @"L1"; temp.l2 = @"L2"; temp.imageURL = @"someImage.jpg"; [self.customInfoWindow initializeWithDetails:temp]; return self.customInfoWindow; } 

有什么build议么?

首先,button不被点击的原因是因为谷歌地图采取UIView并呈现为一个ImageView所以button是图像的一部分,当然不可点击。

解决scheme是添加一个UIView和处理你自己的隐藏/显示和定位。 而不是使用

  • (UIView *)mapView:(GMSMapView *)p_mapView markerInfoWindow:(GMSMarker *)p_marker

我用didTapMarker并返回YES;