如何在InfoWindow中包含一个按钮 [英] How to include a button in InfoWindow

查看:111
本文介绍了如何在InfoWindow中包含一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循本教程关于如何将自定义信息窗口添加到Google地图标记,
在UIView中我添加了一个按钮并创建了一个IBAction,但是当我点击它时什么也没有发生。

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

.h

  #import< UIKit / UIKit.h> 
#importDetails.h

@interface MarkerInfoWindowView:UIView
@property(弱,非原子)IBOutlet UIImageView * imageView;
@property(弱,非原子)IBOutlet UILabel * label1;
@property(弱,非原子)IBOutlet UILabel * label2;
@property(弱,非原子)IBOutlet UIButton * btn1;

- (void)initializeWithDetails:(Details *)p_details;
@end

.m



< pre $ #importMarkerInfoWindowView.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;


$ b - (IBAction)btn1_Clicked:(id)发件人
{
NSLog(@button clicked);
}
@end

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

   - (MarkerInfoWindowView *)customInfoWindow 
{
if(_customInfoWindow == nil)
{
_customInfoWindow = [[[NSBundle mainBundle] loadNibNamed:@MarkerInfoWindowViewowner:self options:nil] objectAtIndex:0];
}

return _customInfoWindow;

$ b - (UIView *)mapView:(GMSMapView *)p_mapView markerInfoWindow:(GMSMarker *)p_marker
{
Details * temp = [[Details alloc]在里面];
temp.l1 = @L1;
temp.l2 = @L2;
temp.imageURL = @someImage.jpg;

[self.customInfoWindow initializeWithDetails:temp];

返回self.customInfoWindow;
}

有什么建议?

解决方案

首先不点击按钮的原因是因为google-maps使用UIView并将其呈现为imageView,因此该按钮是图像的一部分,当然不可点击。 / p>

解决方案是添加一个UIView并处理您自己的隐藏/显示和定位。
而不是


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



我使用了didTapMarker并返回YES;

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?

解决方案

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;

这篇关于如何在InfoWindow中包含一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆