简体   繁体   中英

ios Custom annotation view using storyboard in MapKit

I'm trying to add a custom annotation view in mapkit . When I tap on red annotation pin , I got an annotation callout,but it is very simple.I want to add a custom view which I have made in the storyboard. Can you please provide me a video or text tutorial link or any other kind of help regarding the same.

-(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];
}

My customCallOutDetailView is showing on tapping the annotation,but it's not showing at that annotation pin point, i think the view is taking its coordinates from the origin of the view.

In this method you can add you custom view.

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

 [view addSubview:customView];
}

More information on the following link : How To add custom View in map's Annotation's Callout's

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM