我刚开始使用适用于 iOS 的 Google Maps SDK,但遇到了一些问题。我正在尝试添加以下代码:
- (void)viewDidLoad {
[super viewDidLoad];
// Google map code here...
UITapGestureRecognizer *listTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(listClick:)];
[self.listButton addGestureRecognizer:listTap];
}
- (void)listClick:(UITapGestureRecognizer *)recognizer {
NSLog(@"List button pressed");
}
但它似乎没有在图像上注册点击事件。我已经连接了 IBOutlet,但似乎 Google map 正在采取所有手势。我可以开始平移,将我的鼠标(或手指)放在列表按钮上并滑动, map 只会响应它。
我正在使用适用于 iOS v1.2 的 Google Maps SDK(应该是当前版本)并且目标 iOS 版本是 5.1。任何想法都会有所帮助,因为这让我很生气。
最佳答案
你一定是在开玩笑……这就是发生的事情。 Storyboard 已选中 User Interaction Enabled
,但显然这并不意味着下蹲。我将代码更改为:
UITapGestureRecognizer *listTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(listClick:)];
self.listButton.userInteractionEnabled = YES;
[self.listButton addGestureRecognizer:listTap];
关键在于设置 self.listButton.userInteractionEnabled = YES;
一切都按预期进行,我的 iOS 开发世界不再颠倒。
关于iOS 谷歌地图添加额外的 UIGesturerecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16127375/