gpt4 book ai didi

ios - 自定义信息窗口上的按钮未在 ios 中接收操作

转载 作者:可可西里 更新时间:2023-11-01 04:38:59 26 4
gpt4 key购买 nike

我在 iOS 应用程序中使用谷歌地图,并实现了一个自定义信息窗口来显示标记的标题。
现在,我在那个自定义信息窗口上添加了一个按钮,但我的问题是按钮操作方法没有被调用。

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 调用了 button

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 方法不会触发。

最佳答案

我没有使用过 Google Maps SDK,但在访问了几个链接之后,您似乎想要完成的事情可能并不容易。

引用: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 (using View.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), call showInfoWindow(). 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:委托(delegate)方法检查信息窗口是否被点击。
(缺点是整个信息窗口变成了一个按钮)


其他链接:

similar question 1
similar question 2

关于ios - 自定义信息窗口上的按钮未在 ios 中接收操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23197761/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com