1
votes

all of you. I have been working on map view but i unable solve pinch and tap detection problem.I want to detect pinch and tap in map view.

I have tried following code in iPhone MapView

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

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

Where tap is working but pinch detection is not working.

Please help me.

Thanks in Advanced.

1
"I want to detect pinch and tap in map view." - what have you tried? what didn't work? SO is not a "do my coding for free" site.Mitch Wheat
I have tried with adding UIPanGestureRecognizer,UIPinchGestureRecognizer as GestureRecognizer in map view but it didn't workNitin

1 Answers

3
votes

Add following code in your view did load and add Gesture recognizer delegate in you .h file.

Enjoy...:)

[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];