gpt4 book ai didi

ios - Google map SDK didTapMyLocationButtonForMapView 未在 iOS 7 中调用

转载 作者:搜寻专家 更新时间:2023-10-30 20:17:40 24 4
gpt4 key购买 nike

我正在使用 google maps SDK 1.7.2 在使用 iOS 7 的项目上(我刚刚从 iOS6 升级)。出于某种原因,所有 GMSMapViewDelegate 回调都有效,但 this一个

- (BOOL) didTapMyLocationButtonForMapView: (GMSMapView *)mapView

enter image description here

我假设这应该在点击箭头按钮时调用,对吗?知道为什么不是吗?

这就是我实例化 map View 的方式:

mapView_ = [GMSMapView mapWithFrame:[[self mainView] bounds] 
camera:[self currentCameraUseStandartZoom:YES]];
[[mapView_ settings] setMyLocationButton:YES];
[mapView_ setDelegate:self];
[[self mainView] addSubview:mapView_];

最佳答案

我使用了一种非常可靠的方法来找到我的位置按钮。

最初创建 map View 时,按钮是隐藏的。我通过 map View 层次结构找到所有隐藏的按钮。然后我设置 self.mapView.settings.myLocationButton = YES 并检查我找到的任何按钮是否不再隐藏。

这是我使用的代码:

- (UIButton*)findAndShowMyLocationButton
{
NSMutableArray* hiddenButtons = [NSMutableArray array];
[self findHiddenButtonsInView:self.mapView hiddenButtons:hiddenButtons];
self.mapView.settings.myLocationButton = YES;
for (UIButton* button in hiddenButtons) {
if (!button.hidden) return button;
}
return nil;
}

- (void)findHiddenButtonsInView:(UIView*)view hiddenButtons:(NSMutableArray*)hiddenButtons
{
for (UIView* subview in view.subviews) {
if (subview.hidden && [subview isKindOfClass:[UIButton class]]) {
[hiddenButtons addObject:subview];
} else {
[self findHiddenButtonsInView:subview hiddenButtons:hiddenButtons];
}
}
}

最后

- (void)viewDidLoad
{
...
UIButton* myLocationButton = [self findAndShowMyLocationButton];
[myLocationButton addTarget:self action:@selector(myLocationClick) forControlEvents:UIControlEventTouchUpInside];
}

关于ios - Google map SDK didTapMyLocationButtonForMapView 未在 iOS 7 中调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23515294/

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