Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Mapkit Custom Callout

Tags:

ios

mapkit

Here's a sample custom callout that I'd want to get a similar style of. I was thinking of inheriting from MKAnnotation but I'm lost how to start it and I don't know if the callout's design could be overridden.

http://1.bp.blogspot.com/_xfo3fwc97Fg/TJ9RZrHVOaI/AAAAAAAAAU4/buhP3q3y0G4/s1600/fmip_locate_20100622.png

Any ideas how to implement this custom callout with ui controls inside?

EDIT: Here's my code from following the similar StackOverflow answer:

- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
    if(annotationView)
        return annotationView;
    else
    {
        UIImage *img = [UIImage imageNamed:@"default_thumb.png"];

        MKAnnotationView *annotationView = 
            [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier];
        annotationView.canShowCallout = YES;
        annotationView.image = img;
        annotationView.draggable = YES;

        /*
        // change left accessory view button with image
        UIImageView *leftAccView = [[UIImageView alloc] initWithImage:img];
        annotationView.leftCalloutAccessoryView = leftAccView;

        //include a right button to show more info         
        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [rightButton addTarget:self action:@selector(calloutSubMenu:) forControlEvents:UIControlEventTouchUpInside];
        [rightButton setTitle:annotation.title forState:UIControlStateNormal];
        annotationView.rightCalloutAccessoryView = rightButton;         
         */

        return annotationView;
    }
    return nil;
}

// Customize accessory view
- (void)mapView:(MKMapView *)mapview annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    [mapview deselectAnnotation:view.annotation animated:YES];

    PopOverCallout *popOverCallout = [[PopOverCallout alloc]init];

    UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:popOverCallout];

    self.annotationPopoverController = popOver;

    popOver.popoverContentSize = CGSizeMake(500, 500);

    [popOver presentPopoverFromRect:view.bounds inView:view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];    
}

The

(void)mapView:(MKMapView *)mapview annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control

should be called whenever the pin is touched to show the callout right? but what happens is that a blank regular callout is shown. What might I be doing wrong?

BTW: the UIViewController subclass only has a label on it's XIB and is pretty much blank.

like image 721
Bahamut Avatar asked Aug 23 '11 16:08

Bahamut


1 Answers

Found out the answer after a few mins of nap.

using this as the guide, I just needed to override

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

which shows the annotation callout. Thanks again for the answer, Ms. Anna.

like image 107
Bahamut Avatar answered Oct 18 '22 21:10

Bahamut