iphone - 长按自定义注释图钉更改为默认红色图钉

标签 iphone ios google-maps mkmapview mkpinannotationview

我在应用程序中有自定义注释图钉:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    return [kml viewForAnnotation:annotation type:state];
}

我返回自定义 View 并为 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;
}

但如果我长按我的注释图钉,它会将外观更改为其默认 View (RedPin)。 我无法理解长按调用的是什么方法。我试着玩 UITapGestureRecognizer,但没有发现。如果我只是点击注释图钉一切正常,我的自定义注释图钉 View 不会消失。 你可以在这张截图中看到我的意思: so useful image with example

那么,为什么长按时注释图钉的外观会发生变化?

最佳答案

因此,如果您想为注释 View 使用自定义图像,请始终使用通用 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;
}

关于iphone - 长按自定义注释图钉更改为默认红色图钉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8257203/

相关文章:

android - 如何在 Android 的 MapView 上绘制带边框的文本?

iphone - iOS Storyboard 连接松动?

iphone - 使用后台线程时的iOS View Controller 生命周期

javascript - 谷歌地图地理编码 API 不返回纬度和经度

ios - AFNetworking + HTTPS(未验证身份)

ios - 文本字段应该返回,这对 ios7 是否正确?

javascript - 使用谷歌地图删除路线

iphone - 将.m4a文件添加到资源时,XCode崩溃

ios - Xcode iPhone "digest is missing"

ios - 弹出 View Controller 导致条形按钮项目消失