使用 MapKit 在地图中的 pin(注释)标注中显示自定义 UIView

发布于 2024-10-12 06:20:18 字数 170 浏览 0 评论 0原文

在我的应用程序中,我想在用户触摸地图(标准引脚)上的注释的情况下显示自定义视图(带按钮)。 我知道我可以子类 MKAnnotationView 并更改 pin 的视图。但是我如何更改用户触摸图钉时出现的附加信息视图的外观(默认情况下它显示 MKAnnotation 对象的标题和副标题)。 我该怎么做?

谢谢。

In my application i want to display custom view(with buttons) in the case of user touches annotation on map(standard pin).
i know that i can subclass MKAnnotationView and change the view of pin. but how can i change the look of Additional information view, that appears when user touches pin(by default it displays title and subtitle of MKAnnotation object).
how can i do this?

Thanks.

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

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

发布评论

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

评论(2

转角预定愛 2024-10-19 06:20:18
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )annotation
{
    MKPinAnnotationView *pinView = nil;
    static NSString *defaultPinID = @"ReusedPin";
    pinView = (MKPinAnnotationView*)[mVdequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if ( pinView == nil )
        pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
    if (((PinAnnotationView*)annotation).tag == 0 )
    {
        pinView.pinColor = MKPinAnnotationColorPurple;
    }
    else {
        pinView.pinColor = MKPinAnnotationColorRed;
    }
    pinView.canShowCallout = YES;
    pinView.animatesDrop = YES;
    UIImageView *pinImageView = [[UIImageView alloc] initWithFrame:CGRectMake(-5, 0, 34, 34)];
    UIImage *pinImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"png"]];
    pinImageView.image = pinImage;
    [pinImage release]; 
    [pinView addSubview:pinImageView];
    [pinImageView release];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    btn.tag = ((PinAnnotationView*)annotation).tag;
    pinView.rightCalloutAccessoryView = btn;
    return pinView;
}

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    if ( control.tag !=0) {
        ShowProviderDetailVC  *viewControlle = [[ShowProviderDetailVC alloc]initWithNibName:@"ShowProviderDetailVC" bundle:nil];
        viewControlle.lastViewName = @"SearchView";
        for (NSMutableDictionary* dict in globalLocArray) {
            if ( control.tag ==[[dict valueForKey:@"ID"] intValue] )
            {
                viewControlle.providerInfoDict = dict;
            }
     }
    [self.navigationController pushViewController:viewControlle animated:YES];
    [viewControlle release];
}
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )annotation
{
    MKPinAnnotationView *pinView = nil;
    static NSString *defaultPinID = @"ReusedPin";
    pinView = (MKPinAnnotationView*)[mVdequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if ( pinView == nil )
        pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];
    if (((PinAnnotationView*)annotation).tag == 0 )
    {
        pinView.pinColor = MKPinAnnotationColorPurple;
    }
    else {
        pinView.pinColor = MKPinAnnotationColorRed;
    }
    pinView.canShowCallout = YES;
    pinView.animatesDrop = YES;
    UIImageView *pinImageView = [[UIImageView alloc] initWithFrame:CGRectMake(-5, 0, 34, 34)];
    UIImage *pinImage = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon" ofType:@"png"]];
    pinImageView.image = pinImage;
    [pinImage release]; 
    [pinView addSubview:pinImageView];
    [pinImageView release];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    btn.tag = ((PinAnnotationView*)annotation).tag;
    pinView.rightCalloutAccessoryView = btn;
    return pinView;
}

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
    if ( control.tag !=0) {
        ShowProviderDetailVC  *viewControlle = [[ShowProviderDetailVC alloc]initWithNibName:@"ShowProviderDetailVC" bundle:nil];
        viewControlle.lastViewName = @"SearchView";
        for (NSMutableDictionary* dict in globalLocArray) {
            if ( control.tag ==[[dict valueForKey:@"ID"] intValue] )
            {
                viewControlle.providerInfoDict = dict;
            }
     }
    [self.navigationController pushViewController:viewControlle animated:YES];
    [viewControlle release];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文