Custom MKMapView callout not responding to touch events

谁说我不能喝 提交于 2019-12-06 07:02:43

This is a well known problem. Anything you add on AnnotationView will not detect touches. There is good open source project for this problem. http://dev.tuyennguyen.ca/wp-content/uploads/2011/03/CustomMapAnnotationBlogPart1.zip, http://dev.tuyennguyen.ca/wp-content/uploads/2011/03/CustomMapAnnotationBlogPart21.zip

EDIT:

Yes. I also tried hard to add uibuttons to my own custom annotationView but then I stumbled upon this project and found that his custom annotationView is actually a annotation.

Anyway if you want to to change height of annotatioView then you can set

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{

 calloutMapAnnotationView.contentHeight = height;
 calloutMapAnnotationView.titleHeight = 25;
}

here, titleHeight is property added to CalloutMapAnnotationView which determines height of "gloss" in drawRectMethod

- (void)drawRect:(CGRect)rect {
glossRect.size.height = self.titleHeight;
}

if you are having any difficulty please let me know.

And also the link to original blogpost: http://dev.tuyennguyen.ca/?p=298

I resolved this problem. Click anything in CalloutView,the map will not get touch.My calloutview is custom have tabbleview

1 - In file MapviewController.h you will add delegate : UIGestureRecognizerDelegate

2 - and in file MapViewController.m implement method - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

-In my mapView when you click 1 time on Map it will go in this method 3 time. So I limit touch will action.the first touch will action. - In myCalloutView have tabbleView, if tabbleView receive touch It will return false touch for Map, it will make your tabbleview can get touch.It same for your button.

Note : in NSlog hit test View : will have name of view item you want it have touch. example my view : isEqualToString:@"UITableViewCellContentView"]

static int count=0;
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    NSLog(@"hit test view %@",[touch view]);    
    if(count >0 && count<=2)
    {
        count++;
        count=count%2;
        return FALSE;
    }
    count++;      
    if ([[[[touch view] class] description] isEqualToString:@"UITableViewCellContentView"]) {
        return FALSE;
    }
    return TRUE;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!