1

我试图通过不单击图钉在图钉上显示标注。简而言之,我想在图钉放置在地图上时显示标注。

这是我正在使用的代码:

-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation         //  Method to handle all the annotations on map.
{

    if([annotation isKindOfClass: [MKUserLocation class]])
        return nil;

    static NSString *annotationID = @"MyAnnotation";

    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationID] ;

    if (!pinView) {
        pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationID];
        pinView.canShowCallout = YES;
        pinView.image = [UIImage imageNamed:@"map_pin.png"];

        //Setting Right call button
        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

        //Setting Left Call button
        self.favButton = [UIButton buttonWithType:UIButtonTypeCustom];
        self.favButton.frame = CGRectMake(0, 0, 23, 23);
        self.favButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        self.favButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [self.favButton setImage:[UIImage imageNamed:@"favourite.png"] forState:UIControlStateNormal];
        pinView.leftCalloutAccessoryView = self.favButton;

        [self.mapView selectAnnotation:annotation animated:YES];
    }
    return pinView;

}

任何帮助都是不言而喻的。

4

1 回答 1

0

试试这个:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{
    for (id<MKAnnotation> currentAnnotation in mapView.annotations) {
        if ([currentAnnotation isEqual:annotationToSelect]) {
            [mapView selectAnnotation:currentAnnotation animated:YES];
        }
    }
}

或者

编辑 :-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation // 处理地图上所有注释的方法。{

if([annotation isKindOfClass: [MKUserLocation class]])
    return nil;

static NSString *annotationID = @"MyAnnotation";

MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:annotationID] ;

if (!pinView) {
    pinView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:annotationID];
    pinView.canShowCallout = YES;
    pinView.image = [UIImage imageNamed:@"map_pin.png"];

    //Setting Right call button
    pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

    //Setting Left Call button
    self.favButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.favButton.frame = CGRectMake(0, 0, 23, 23);
    self.favButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    self.favButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [self.favButton setImage:[UIImage imageNamed:@"favourite.png"] forState:UIControlStateNormal];
    pinView.leftCalloutAccessoryView = self.favButton;

            **[self performSelector:@selector(selectAnnotation:) withObject:annotation afterDelay:0.5];**

}
return pinView;

}

- (void)selectAnnotation:(id < MKAnnotation >)annotation
{
    [self.mapView selectAnnotation:annotation animated:NO];
}
于 2013-07-01T10:34:29.983 回答