我在app上有一个自定义的注解图钉:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
return [kml viewForAnnotation:annotation type:state];
}其中我返回自定义视图,并为Placemark的annotationView生成setImage,例如:
- (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)point type:(int)state
{
// Find the KMLPlacemark object that owns this point and get
// the view from it.
for (KMLPlacemark *placemark in _placemarks) {
if ([placemark point] == point)
{
UIButton *disclosureButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
[[placemark annotationView] setCanShowCallout: YES];
[[placemark annotationView] setRightCalloutAccessoryView:disclosureButton];
if (state == 0)
{
[[placemark annotationView] setImage:[UIImage imageNamed:@"ic_pin_tour.png"]];
}
else
{
[[placemark annotationView] setImage:[UIImage imageNamed:@"ic_pin_point.png"]];
}
return [placemark annotationView];
}
}
return nil;
}但如果我长时间点击我的注解别针,它会将外观更改为其默认视图(RedPin)。我不明白在long tap上调用了什么方法。我试着玩UITapGestureRecognizer,但没有发现。如果我只是点击注解别针,一切都很好,我的自定义注解别针视图也不会消失。你可以在这个截图中看到我的意思:

那么,为什么注释引脚的外观在长时间点击时会发生变化?
发布于 2011-11-24 21:19:41
因此,如果您希望在注释视图中使用自定义图像,请始终使用通用MKAnnotationView而不是MKPinAnnotationView。我只在一个地方有MKPinAnnotationView,当我用MKAnnotationView替换它时,现在一切都正常了:
- (MKAnnotationView *)annotationView
{
if (!annotationView) {
id <MKAnnotation> annotation = [self point];
if (annotation) {
MKAnnotationView *pin =
[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
pin.canShowCallout = YES;
annotationView = pin;
}
}
return annotationView;
}https://stackoverflow.com/questions/8257203
复制相似问题