How to trigger MKAnnotationView's callout view without touching the pin?

后端 未结 13 2399
时光取名叫无心
时光取名叫无心 2020-11-29 19:57

I\'m working on a MKMapView with the usual colored pin as the location points. I would like to be able to have the callout displayed without touching the pin.

13条回答
  •  伪装坚强ぢ
    2020-11-29 20:08

    After trying a variety of answers to this thread, I finally came up with this. It works very reliably, I have yet to see it fail:

    - (void)mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views;
    {
        for(id currentAnnotation in aMapView.annotations) 
        {       
            if([currentAnnotation isEqual:annotationToSelect]) 
            {
                NSLog(@"Yay!");
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_current_queue(), ^
                {
                    [aMapView selectAnnotation:currentAnnotation animated:YES];
                });
            }
        }
    }
    

    The block is used to delay slightly, as without it the callout may not be shown correctly.

提交回复
热议问题