を長押しすると、奇妙な動作が発生することがわかりました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;
}
}