Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use a <code>UIGestureRecognizer</code> to detect touches on the map view.</p> <p>Instead of a single tap, however, I would suggest looking for a double tap (<code>UITapGestureRecognizer</code>) or a long press (<code>UILongPressGestureRecognizer</code>). A single tap might interfere with the user trying to single tap on the pin or callout itself.</p> <p>In the place where you setup the map view (in <code>viewDidLoad</code> for example), attach the gesture recognizer to the map view:</p> <pre><code>UITapGestureRecognizer *tgr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)]; tgr.numberOfTapsRequired = 2; tgr.numberOfTouchesRequired = 1; [mapView addGestureRecognizer:tgr]; [tgr release]; </code></pre> <p>or to use a long press:</p> <pre><code>UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)]; lpgr.minimumPressDuration = 2.0; //user must press for 2 seconds [mapView addGestureRecognizer:lpgr]; [lpgr release]; </code></pre> <p><br /> In the <code>handleGesture:</code> method:</p> <pre><code>- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer { if (gestureRecognizer.state != UIGestureRecognizerStateEnded) return; CGPoint touchPoint = [gestureRecognizer locationInView:mapView]; CLLocationCoordinate2D touchMapCoordinate = [mapView convertPoint:touchPoint toCoordinateFromView:mapView]; MKPointAnnotation *pa = [[MKPointAnnotation alloc] init]; pa.coordinate = touchMapCoordinate; pa.title = @"Hello"; [mapView addAnnotation:pa]; [pa release]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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