#pragma mark - MKMapViewDelegate
-(MKAnnotationView*)mapView:(MKMapView*)mapView viewForAnnotation:(id)annotation
{
NSString*identifer =@"SMAnonotationView";
SMAnonotationView*anonotationView = (SMAnonotationView*)[mapViewviewForAnnotation:annotation];
if(!anonotationView) {
anonotationView = [[SMAnonotationViewalloc]initWithAnnotation:annotationreuseIdentifier:identifer];
anonotationView.model=self.anonotionModel;
anonotationView.delegate=self;
}
anonotationView.delegateView=self;
returnanonotationView;
}
換上自定義大頭針后,發現其frame為0,無法點擊,之后思路
1.加frame,但位置不對達不到預期效果
2.-(void)mapView:(MKMapView*)mapView didSelectAnnotationView:(MKAnnotationView*)view
{
DebugLog(@"didSelectAnnotationView");
}
這個方法在系統大頭針會調用,而且一旦點擊將被選擇,有坑,躲開
3.- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
{
UIView*fitView = [superhitTest:pointwithEvent:event];
//轉換坐標系
CGPointnewPoint = [self.anonotationViewconvertPoint:pointfromView:self];
//判斷觸摸點是否在view上
if(CGRectContainsPoint(self.anonotationView.bounds, newPoint)) {
fitView =self.anonotationView;
returnfitView;
}
returnnil;
}
此為正確方法,獲取超出super view的點擊事件。