【问题标题】:How to include a button in InfoWindow如何在 InfoWindow 中包含一个按钮
【发布时间】:2013-08-08 03:09:44
【问题描述】:

我关注了this tutorial,了解如何将自定义信息窗口添加到谷歌地图标记, 在 UIView 中,我添加了一个按钮并创建了一个 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;
}

有什么建议吗?

【问题讨论】:

  • 你的代码是什么样的?
  • @geocodezip 添加了代码(虽然与教程中的相同)

标签: ios xcode google-maps google-maps-markers infowindow


【解决方案1】:

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

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

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

我使用了 didTapMarker 并返回 YES;

【讨论】:

  • 没错。我不得不重写更多方法,包括 mapView:markerInfoWindow: 我不明白为什么信息窗口被渲染为图像。
猜你喜欢
  • 1970-01-01
  • 2013-02-07
  • 2021-08-02
  • 1970-01-01
  • 1970-01-01
  • 2014-09-29
  • 1970-01-01
  • 2021-12-24
  • 1970-01-01
相关资源
最近更新 更多