使用MapKit中的故事板进行ios自定义注释视图

我正在尝试在mapkit中添加自定义注释视图 . 当我点击红色注释引脚时,我得到了一个注释标注,但它非常简单 . 我想添加一个我在故事板中制作的自定义视图 . 能否请您提供视频或文字教程链接或任何其他类型的帮助 .

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{

    if([view isKindOfClass:[MKUserLocation class]]){

        return ;
    }

    CLLocationCoordinate2D optimusInfoCallOut = CLLocationCoordinate2DMake(28.625551, 77.373268);

    [self.mapView setRegion:MKCoordinateRegionMakeWithDistance(optimusInfoCallOut, 800, 800)animated:YES];

    UIImageView *imgView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loc.png"]];

    CGRect calloutViewFrame = imgView.frame;
    imgView.frame = CGRectMake(calloutViewFrame.size.width/8.0, calloutViewFrame.size.height-24, 200, 100);

    CustomPointAnnotation *cpa = [[CustomPointAnnotation alloc] init];
    cpa.name = @"OpTi";
    cpa.imgName1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"loc.png"]];
    self.customCallOutDetailsView.name.text = cpa.name;
    self.customCallOutDetailsView.callImage = cpa.imgName1;

    [self.view addSubview:self.customCallOutDetailsView];
}

我的customCallOutDetailView在点击注释时显示,但它没有显示在该注释引脚点,我认为视图是从视图的原点获取其坐标 .

回答(1)

2 years ago

在此方法中,您可以添加自定义视图 .

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{

 [view addSubview:customView];
}

有关以下链接的更多信息:How To add custom View in map's Annotation's Callout's