How to include a button in InfoWindow

自闭症网瘾萝莉.ら 提交于 2019-12-24 15:27:50

问题


I followed this tutorial on how to add custom info window to a google map marker, in the UIView I've added a button and created an IBAction but when I click on it nothing happen

my infoWindow view code looks like this

.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

and then in my view controller of the main screen and map

-(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;
}

any suggestions?


回答1:


first the reason for the button not being clicked is because google-maps takes the UIView and renders it as an imageView so the button is part of an image and of course not clickable.

the solution is to add a UIView and handle on your own the hide/show and positioning. instead of using

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

i used didTapMarker and returned YES;



来源:https://stackoverflow.com/questions/18091564/how-to-include-a-button-in-infowindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!