gpt4 book ai didi

ios - GMSMapView touchesbegan 仅触发一次

转载 作者:可可西里 更新时间:2023-11-01 03:28:50 24 4
gpt4 key购买 nike

我正在尝试扩展 GMSMapView 以创建一些聚类功能,我需要检测用户何时开始移动 map 以禁用聚类渲染并在完成时再次启用它。

我重写了 touchesbegan 和 touchesended,但 touchesbegan 只调用了一次。覆盖 hittest 后,我​​能够看到 GMSVectorMapView 处理 GMSMapView 触摸,如果我更改此函数的返回, map 不会移动。

有什么方法可以捕获此事件或在用户与 map 交互时执行某些操作。

最好的问候,马龙·皮娜·托贾尔

最佳答案

我不确定我是否完全理解您需要检测哪些触摸或为什么/如何需要检测它们。但是,由于 touchesbegan: only being called once,我在检测 GMSMapView 顶部的用户平移手势时遇到了类似的问题。

我有自己的“当前位置”按钮,让用户可以打开/关闭以他们的位置为中心的 map 。我需要找出用户何时“平移” map 而不中断 map 对平移的接收(我仍然希望 map 也能平移)。

首先,我创建了 map :

// Creates Map centered at current location
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:theLocationManager.location.coordinate.latitude
Longitude:theLocationManager.location.coordinate.longitude
zoom:15];
theMapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
theMapView.myLocationEnabled = YES;
theMapView.delegate = self;
theMapView.camera = camera;
self.view = theMapView;

然后我创建了一个平移手势识别器并将其添加到 theMapView 的手势识别器属性中。我确保使用选择器方法 didPan:

将目标设置为 self
// Watch for pan
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget: self action:@selector(didPan:)];
theMapView.gestureRecognizers = @[panRecognizer];

最后,在同一个主文件中,我实现了 didPan: 方法以在用户平移时使用react:

- (void) didPan:(UIPanGestureRecognizer*) gestureRecognizer
{
NSLog(@"DID PAN");
// React here to user's pan
}

关于ios - GMSMapView touchesbegan 仅触发一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16842713/

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