长按时我发现了一些奇怪的行为MKPointAnnotation
。
我这样创建我的图钉:
MKPointAnnotation *activeTRPoint = [[MKPointAnnotation alloc] init];
CLLocation *coord = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude];
activeTRPoint.coordinate = coord.coordinate;
activeTRPoint.title = @"Title";
activeTRPoint.subtitle = @"subtitle";
//Added tag
[map addAnnotation:activeTRPoint];
[[map viewForAnnotation:activeTRPoint] setTag:1];
UIImage *im = [UIImage imageNamed:@"pin_icon.png"];
[[map viewForAnnotation:activeTRPoint] setImage:im];
因此,当我长按引脚时,它会变为红色引脚(默认)。你知道为什么会这样吗?
更新:为进一步调查添加了 viewForAnnotation 方法
- (MKAnnotationView *) mapView:(MKMapView *)mapView1 viewForAnnotation:(id <MKAnnotation>) annotation
{
if(annotation != map.userLocation){
// This is not the users location indicator (the blue dot)
MKAnnotationView *view = [map dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"];
BOOL isCustomPin = [subtitles containsObject:((MKPointAnnotation*)annotation).subtitle];
if (!view && isCustomPin == NO) {
// Creating a new annotation view, in this case it still looks like a pin
MKPinAnnotationView *annView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"];
annView.pinColor = MKPinAnnotationColorGreen;
view = annView;
view.canShowCallout = YES; // So that the callout can appear
UIButton *btnViewVenue = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[btnViewVenue addTarget:self action:@selector(pinTouched:) forControlEvents:UIControlEventTouchUpInside];
view.rightCalloutAccessoryView = btnViewVenue;
view.enabled = YES;
view.canShowCallout = YES;
view.multipleTouchEnabled = NO;
}else{
UIImage *im = [UIImage imageNamed:@"pin_icon.png"];
[view setImage:im];
}
return view;
}else{
mapView1.userLocation.title = [Lang get:@"USER_CURRENT_LOCATION"];
mapView1.userLocation.subtitle = @"";
[mapView1 setTag:999];
return nil;
}
}