Touch Detection on MK ANNOTATION

I have an annotation on the map. When I select the annotation, I will show you a call bubble with a custom view. Now when I click on the callout bubble, I want to go to the new view controller, but the tooltip view disappears when I click 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];
    }
}
+4
source share
2 answers

I am not an expert, but you can add UITapGestureRecognizer to your view.

Use the following code:

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

and

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

The bubble has no logic, you need to use the accessory for the leader. So, use the MapView delegation method:

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

And add a leader in viewForAnnotation delegate mode. For instance:

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

, .

0

All Articles