开发者

Automatic "canShowCallOut" annotation iPhone

In which way could I call the function that automatica开发者_Go百科lly opens my annotation (with title, subtitle, etc), rather than to touch on the annotation on the mapview?


Implement MKMapViewDelegate delegate;

Implement - (MKAnnotationView *) mapView: (MKMapView *) mapView_ viewForAnnotation: (id <MKAnnotation>) annotation_;; for example like this:

    - (MKAnnotationView *) mapView: (MKMapView *) mapView_ viewForAnnotation: (id <MKAnnotation>) annotation_ {

    MKPinAnnotationView *pin = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"YourPinId"];
    if (pin == nil) {
        pin = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation_ reuseIdentifier: @"YourPinId"] autorelease];
    }
    else {
        pin.annotation = annotation_;
    }
    pin.pinColor = MKPinAnnotationColorRed;
    [pin setCanShowCallout:YES];
    pin.animatesDrop = YES;
    return pin;
}

Show the pin after the map has finished loading:

- (void) dropPin {
    [mapView addAnnotation:self.annotation];
    [mapView selectAnnotation:self.annotation animated:YES];        
}

- (void) mapViewDidFinishLoadingMap: (MKMapView *) mapView_ {
    // if done loading, show the call out
    [self performSelector:@selector(dropPin) withObject:nil afterDelay:0.3];
}

This code has a property called annotation which implements MKAnnotation. Also, it animates the pin drop too, but it should be fairly self-explaining.

HTH.


Alfons answered the question but if you are looking for what exactly automatically opens the callout, it's this part:

[mapView selectAnnotation:annotation animated:YES]; 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜