现在,我在该自定义信息窗口上添加了一个按钮,但我的问题是没有调用按钮操作方法.
CustomInfoWindow.h
#import <UIKit/UIKit.h> @interface CustomInfoWindow : UIView @property (nonatomic,weak) IBOutlet UILabel *addressLabel; @property(nonatomic) IBOutlet UIButton *button; @end
在infoWindow.xib中,我添加了
> UILabel称为addressLabel
> UIButton称为按钮
ViewController.h
#import "CustomInfoWindow.h" @interface viewController : UIViewController<GMSMapViewDelegate> { GMSMapView *mapView; } @end
ViewController.m
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker { NSLog(@"Mrker Tapped"); CustomInfoWindow *infoWindow = [[[NSBundle mainBundle]loadNibNamed:@"infoWindow" owner:self options:nil] objectAtIndex:0]; infoWindow.addressLabel.text = marker.title; [infoWindow.button addTarget:self action:@selector(ButtonPressed) forControlEvents:UIControlEventTouchUpInside]; return infoWindow; } -(void)ButtonPressed { NSLog(@"Button Pressed"); }
基本上…… ButtonPressed方法不会触发.
解决方法
ref:https://developers.google.com/maps/documentation/android/infowindows
PS:这可能是Android文档,但它似乎也适用于iOS.
报价:
Note: The info window that is drawn is not a live view. The view is
rendered as an image (usingView.draw(Canvas)
) at the time it is
returned. This means that any subsequent changes to the view will not
be reflected by the info window on the map. To update the info window
later (for example,after an image has loaded),callshowInfoWindow()
.
Furthermore,the info window will not respect any of the interactivity
typical for a normal view such as touch or gesture events. However you
can listen to a generic click event on the whole info window as
described in the section below.
您可以改为实施GMSMapViewDelegate’s -didTapInfoWindowOfMarker:
委托方法来检查信息窗是否被点击.
(缺点是整个infowindow成为一个按钮)
其他链接:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。