iPhone:MKPinAnnotationView:当前位置具有与其他引脚相同的注释视图。如何让它与众不同?

时间:2011-05-24 00:30:04

标签: iphone annotations mkmapview

我使用以下方法在我的mapView上显示MKAnnotation View。但我们这样做,用户的当前位置也被赋予与其他引脚相同的视图。如何使当前位置成为唯一的针脚颜色

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] 
                                  initWithAnnotation:annotation 
                                  reuseIdentifier:@"currentloc"];
    //annView.pinColor = MKPinAnnotationColorGreen;

     UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
     myDetailButton.frame = CGRectMake(0, 0, 23, 23);
     myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
     myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    [myDetailButton addTarget:self 
                        action:nil/*@selector(checkButtonTapped:event:)*/ 
              forControlEvents:UIControlEventTouchUpInside];

    annView.rightCalloutAccessoryView = myDetailButton;

    annView.animatesDrop=NO;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    return annView;
}

1 个答案:

答案 0 :(得分:2)

viewForAnnotation方法中,检查注释是否是MKUserLocation的实例。如果是,请返回nil

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