如何在地图视图中检测到夹点和点击?

时间:2012-01-02 06:06:51

标签: iphone xcode4

你们所有人。我一直在研究地图视图,但我无法解决捏合和点击检测问题。我想检测夹点并点击地图视图。

我在iPhone MapView中尝试过以下代码

UITapGestureRecognizer * Tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(checktap)];     [self.mapView addGestureRecognizer:Tap];     [点击发布];

UIPinchGestureRecognizer * pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(checkpinch)];     [self.mapView addGestureRecognizer:pinch];     [捏释];

水龙头工作但夹点检测不起作用。

请帮帮我。

感谢高级。

1 个答案:

答案 0 :(得分:3)

在您的视图中添加以下代码,并在您的.h文件中添加Gesture识别器代理。

...享受:)

[self.view insertSubview:mapView atIndex:0];

//Gesture reconizer
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(checkpinch)];
[pinch setDelegate:self];
[pinch setDelaysTouchesBegan:YES];
[self.mapView addGestureRecognizer:pinch];
[pinch release];

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(checktap)];
[singleTap setDelegate:self];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired =2;
[self.mapView addGestureRecognizer:singleTap];
[singleTap release];


UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(checktap)];
[doubleTap setDelegate:self];
doubleTap.numberOfTapsRequired = 2;
doubleTap.numberOfTouchesRequired =1;
[self.mapView addGestureRecognizer:doubleTap];
[doubleTap release];