我们正在为 iPhone 开发基于 map 的应用程序。我们需要检测 MapView 上拖动和捏合手势的开始。
我们能够使用 regionWillChange 委托(delegate)方法检测拖动的开始。我们无法检测到捏合手势的开始。
我们正在寻找一种检测捏合手势开始的方法。在 MapView 上可以吗?
提前致谢。
编辑:
我们尝试了以下代码,但没有成功。
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self actionselector(checkpinch)];
[self.mapView addGestureRecognizer:pinch];
[pinch release];
双击手势识别器正在使用类似代码在 MapView 上工作。
UITapGestureRecognizer *Tap= [[UITapGestureRecognizer alloc]initWithTarget:self actionselector(checktap)];
[self.mapView addGestureRecognizer:Tap];
[Tap release];
Best Answer-推荐答案 strong>
完美而简单的解决方案。
首先在你的.h文件中添加UIGestureRecognizerDelegate
而不是在你的 .m 文件中添加以下两种方法
-(BOOL)gestureRecognizerUIGestureRecognizer *)gestureRecognizer shouldReceiveTouchUITouch *)touch
{
return YES;
}
-(BOOL)gestureRecognizerUIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizerUIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
-(BOOL)gestureRecognizerShouldBeginUIGestureRecognizer *)gestureRecognizer
{
return YES;
}
在 viewdidload 中进行以下更改
[self.view insertSubview:mapView atIndex:0];
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self actionselector(yourmethod)];
[pinch setDelegate:self];
[pinch setDelaysTouchesBegan:YES];
[self.mapView addGestureRecognizer:pinch];
[pinch release];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self actionselector(youemethod)];
[tap setDelegate:self];
[self.mapView addGestureRecognizer:tap];
[tap release];
关于iphone - 检测从 iPhone MapView 开始的捏合手势,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/8708518/
|