【问题标题】:Annotation Image is replaced by RedPushPin when long press on annotation长按注释时,注释图像被 RedPushPin 替换
【发布时间】:2012-03-05 18:23:19
【问题描述】:

我创建了以下自定义注释:

-(MKAnnotationView*)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{
    MKPinAnnotationView *view = nil;
    if (annotation != mapView.userLocation)
    {
        view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"myAnnotationIdentifier"];
        if (!view) 
            view = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"myAnnotationIdentifier"];

        if (((CustomAnnotation *)annotation).annotationType == 1)
        {
            view.image = [UIImage imageNamed:@"type1.png"];
            view.rightCalloutAccessoryView = nil;
            view.canShowCallout = YES;
        }
        else
        {
            view.image = [UIImage imageNamed:@"type2.png"];
            view.rightCalloutAccessoryView = nil;
            view.canShowCallout = YES;
        }
    }
return view;
}

问题:当用户在任何注释图像(type1 或 type2)上按住 2 秒时,Image 会被 Red PushPin 替换(iPhone MKPinAnnotationView 的默认设置)。

我想避免这种替换。我该怎么做?

【问题讨论】:

    标签: objective-c mkmapview mkannotationview


    【解决方案1】:

    不要声明和创建MKPinAnnotationView,而是声明并创建一个普通的MKAnnotationView

    MKPinAnnotationView 喜欢默认为红色引脚,这就是它的用途。

    【讨论】:

    • 我也想知道,能不能把RedPushPin放到MKAnnotationView上?
    • 由于您使用自己的图像作为注释视图,因此您应该使用 MKAnnotationView。但是,是的,您可以拥有一些 MKAnnotationView 和一些 MKPinAnnotationView 的注释(不要在这些注释上设置图像)。为每个类使用单独的重用 ID。
    【解决方案2】:

    使用didDeselectAnnotationViewdidSelectAnnotationView 并像您所做的那样重新选择图像:-

    view.image = [UIImage imageNamed:@"type2.png"];
    

    【讨论】:

      猜你喜欢
      • 2020-06-22
      • 2010-12-18
      • 1970-01-01
      • 2014-10-08
      • 2011-10-27
      • 1970-01-01
      • 2012-07-28
      • 2021-04-26
      • 2010-10-07
      相关资源
      最近更新 更多