4
votes

I have an annotation on the map. When I select a annotation I will display callout bubble with custom view. Now when I click on the callout bubble I want to go to new view controller but callout view disappears when I tap on the view.

-(void)mapView:(MKMapView *)mapView1 didSelectAnnotationView:(MKAnnotationView *)view
{
    NSLog(@"selected");
    if(![view.annotation isKindOfClass:[MKUserLocation class]])
    {
        CustomInfoWindow *calloutView =  [[[NSBundle mainBundle] 
        loadNibNamed:@"infoWindow"owner:self options:nil] objectAtIndex:0];
        CGRect calloutViewFrame = calloutView.frame;
        calloutViewFrame.origin = CGPointMake(-calloutViewFrame.size.width/2 + 15, -calloutViewFrame.size.height);
        calloutView.frame = calloutViewFrame;
        [calloutView.imagePlace.layer setBorderColor: [[UIColor orangeColor] CGColor]];
        [calloutView.imagePlace.layer setBorderWidth: 3.0];

        NSData* imageData = [[NSData alloc] initWithContentsOfURL:
        [NSURL  URLWithString:@"http://farm3.staticflickr.com/2926/14605349699_67a1d51b80.jpg"]];
        UIImage* image = [[UIImage alloc] initWithData:imageData];
        [calloutView.imagePlace setImage:image];
        [view addSubview:calloutView];
    }
}

-(void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view 
{
    for (UIView *subview in view.subviews ){
        [subview removeFromSuperview];
    }
}
2

2 Answers

0
votes

I'm no expert but you may want to add a UITapGestureRecognizer to your view.

Use the following code:

UITapGestureRecognizer *tgr = [[UITabGestureRecognizer alloc] initWithTarget:self action:@selector(showNextView)];
calloutView.addGestureRecognizer(tgr);

and

- (void)showNextView {
    ...
}
0
votes

The bubble does not have logic, you need use callout accessory. So, use MapView delegate method:

- (void)mapView:(MKMapView *)mv annotationView:(MKAnnotationView *)pin calloutAccessoryControlTapped:(UIControl *)control;

And add callout at viewForAnnotation delegate method. For example:

UIButton *myDetailAccessoryButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
myDetailAccessoryButton.frame = CGRectMake(0, 0, 23, 23);
myDetailAccessoryButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailAccessoryButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
pinView.rightCalloutAccessoryView = myDetailAccessoryButton;

I hope my answer helps you.