3

在此处输入图像描述我在地图中将点作为引脚注释并显示自定义注释视图。我的问题是,当我单击点时,有时自定义注释视图后面的点会出现在自定义注释视图的前面,而不是显示在它后面。

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{ 
    MKAnnotationView *annotationView;
    PinAnnotationView *pinView = nil;
    NSString *identifier;
    if ([annotation isKindOfClass:[DisplayMap class]]) 
    {
        identifier = @"Pin";
        NSInteger myid = ((DisplayMap *)annotation).takeid;
        MKAnnotationView *pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        DisplayMap *a = (DisplayMap *)annotation;
        pinView.annotation=a;
        if (myid == 1) 
        {
           UIImage *test = [UIImage imageNamed:@"red_dot.png"];
           pinView.image = test;
           pinView.opaque = NO;
       }
       else if (myid == 2)
       {
           UIImage *test = [UIImage imageNamed:@"blue_dot.png"];
           pinView.image = test;
           pinView.opaque = NO;
       }
       else {
           UIImage *test = [UIImage imageNamed:@"green_dot.png"];
           pinView.image = test;
           pinView.opaque = NO;
       }
    return pinView;
  }
  else if ([annotation isKindOfClass:[CalloutAnnotation class]])
  {
       identifier = [NSString stringWithFormat:@"Callout%d",pinView.tag];
       annotationView = [[CalloutAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
       CalloutAnnotation *calloutAnnotation = (CalloutAnnotation *)annotation;
       ((CalloutAnnotationView *)annotationView).title = calloutAnnotation.title;
       ((CalloutAnnotationView *)annotationView).iTag = calloutAnnotation.iTag;
       [annotationView setNeedsDisplay];
       [UIView animateWithDuration:0.5f
                     animations:^(void) {
                         mapView.centerCoordinate = calloutAnnotation.coordinate;
                     }];
       annotationView.annotation = annotation;
       return annotationView;
  }
}


-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view1
{
    if ([view1.annotation isKindOfClass:[DisplayMap class]])
    {
    DisplayMap *pinAnnotation = ((DisplayMap *)view1.annotation);
    LoginDetail *obj =    [[appDelegate mapArray] objectAtIndex:pinAnnotation.iTag];
    [mapView removeAnnotations:annotationRemoveArray];

    CalloutAnnotation *calloutAnnotation = [[CalloutAnnotation alloc] init];
    calloutAnnotation.title      = pinAnnotation.title;
    pinAnnotation.calloutAnnotation = calloutAnnotation;
    [mapView addAnnotation:calloutAnnotation];
    [annotationRemoveArray addObject:calloutAnnotation];
    [self setzoomonselectannotation:pinAnnotation.coordinate];
    }
}
4

1 回答 1

0

标注窗口也是一个注释视图。那是错的 ;)

遵循提示: 如何自定义 MKAnnotationView 的标注气泡?

基本上他们所说的:使标注成为图钉本身的子视图

于 2013-05-28T11:12:57.237 回答