首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >长点击时,自定义注记图钉将更改为默认红色图钉

长点击时,自定义注记图钉将更改为默认红色图钉
EN

Stack Overflow用户
提问于 2011-11-24 20:39:17
回答 1查看 3.6K关注 0票数 8

我在app上有一个自定义的注解图钉:

代码语言:javascript
运行
复制
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    return [kml viewForAnnotation:annotation type:state];
}

其中我返回自定义视图,并为Placemark的annotationView生成setImage,例如:

代码语言:javascript
运行
复制
- (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,但没有发现。如果我只是点击注解别针,一切都很好,我的自定义注解别针视图也不会消失。你可以在这个截图中看到我的意思:

那么,为什么注释引脚的外观在长时间点击时会发生变化?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-11-24 21:19:41

因此,如果您希望在注释视图中使用自定义图像,请始终使用通用MKAnnotationView而不是MKPinAnnotationView。我只在一个地方有MKPinAnnotationView,当我用MKAnnotationView替换它时,现在一切都正常了:

代码语言:javascript
运行
复制
- (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;
}
票数 23
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8257203

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档