iPhone:MKMapAnnotationView:当前位置与其他图钉具有相同的注释视图。如何让它独一无二?

发布于 2024-11-08 22:51:14 字数 1157 浏览 0 评论 0原文

我使用以下方法在我的地图视图上显示 MKAnnotation 视图。但我这样做时,用户的当前位置也具有与其他引脚相同的视图。如何使当前位置具有独特的图钉颜色

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] 
                                  initWithAnnotation:annotation 
                                  reuseIdentifier:@"currentloc"];
    //annView.pinColor = MKPinAnnotationColorGreen;

     UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
     myDetailButton.frame = CGRectMake(0, 0, 23, 23);
     myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
     myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    [myDetailButton addTarget:self 
                        action:nil/*@selector(checkButtonTapped:event:)*/ 
              forControlEvents:UIControlEventTouchUpInside];

    annView.rightCalloutAccessoryView = myDetailButton;

    annView.animatesDrop=NO;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    return annView;
}

Im using the following method to show MKAnnotation View on my mapView. But wehn I do that the current location of the user is also given the same view as the other pins. How can I make the current location a Unique pin color

    - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] 
                                  initWithAnnotation:annotation 
                                  reuseIdentifier:@"currentloc"];
    //annView.pinColor = MKPinAnnotationColorGreen;

     UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
     myDetailButton.frame = CGRectMake(0, 0, 23, 23);
     myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
     myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

    [myDetailButton addTarget:self 
                        action:nil/*@selector(checkButtonTapped:event:)*/ 
              forControlEvents:UIControlEventTouchUpInside];

    annView.rightCalloutAccessoryView = myDetailButton;

    annView.animatesDrop=NO;
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    return annView;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔戏命师 2024-11-15 22:51:14

在您的 viewForAnnotation 方法中,检查注释是否是 MKUserLocation。如果是,则返回nil

if ([annotation isMemberOfClass:[MKUserLocation class]]) return nil;

In your viewForAnnotation method, check to see if the annotation is an instance of MKUserLocation. If it is, return nil:

if ([annotation isMemberOfClass:[MKUserLocation class]]) return nil;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文