Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I setup a long press (<code>UILongPressGestureRecognizer</code>) in <code>viewDidLoad:</code> but it just detect the only one touch from the first.</p> <p><strong>Where can i setup a long press to detect all touch?</strong> (it means the map ready everytime waiting user touch to screen to push a pin)</p> <p>The <code>viewDidLoad:</code> method!</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad];mapView.mapType = MKMapTypeStandard; UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGesture:)]; [self.mapView addGestureRecognizer:longPressGesture]; [longPressGesture release]; mapAnnotations = [[NSMutableArray alloc] init]; MyLocation *location = [[MyLocation alloc] init]; [mapAnnotations addObject:location]; [self gotoLocation]; [self.mapView addAnnotations:self.mapAnnotations]; } </code></pre> <p>and the <code>handleLongPressGesture</code> method:</p> <pre><code>-(void)handleLongPressGesture:(UIGestureRecognizer*)sender { // This is important if you only want to receive one tap and hold event if (sender.state == UIGestureRecognizerStateEnded) {NSLog(@"Released!"); [self.mapView removeGestureRecognizer:sender]; } else { // Here we get the CGPoint for the touch and convert it to latitude and longitude coordinates to display on the map CGPoint point = [sender locationInView:self.mapView]; CLLocationCoordinate2D locCoord = [self.mapView convertPoint:point toCoordinateFromView:self.mapView]; // Then all you have to do is create the annotation and add it to the map MyLocation *dropPin = [[MyLocation alloc] init]; dropPin.latitude = [NSNumber numberWithDouble:locCoord.latitude]; dropPin.longitude = [NSNumber numberWithDouble:locCoord.longitude]; // [self.mapView addAnnotation:dropPin]; [mapAnnotations addObject:dropPin]; [dropPin release]; NSLog(@"Hold!!"); NSLog(@"Count: %d", [mapAnnotations count]); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload