#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;
}
換上自定義大頭針后,發(fā)現(xiàn)其frame為0,無(wú)法點(diǎn)擊,之后思路
1.加frame,但位置不對(duì)達(dá)不到預(yù)期效果
2.-(void)mapView:(MKMapView*)mapView didSelectAnnotationView:(MKAnnotationView*)view
{
DebugLog(@"didSelectAnnotationView");
}
這個(gè)方法在系統(tǒng)大頭針會(huì)調(diào)用,而且一旦點(diǎn)擊將被選擇列疗,有坑俊嗽,躲開(kāi)
3.- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
{
UIView*fitView = [superhitTest:pointwithEvent:event];
//轉(zhuǎn)換坐標(biāo)系
CGPointnewPoint = [self.anonotationViewconvertPoint:pointfromView:self];
//判斷觸摸點(diǎn)是否在view上
if(CGRectContainsPoint(self.anonotationView.bounds, newPoint)) {
fitView =self.anonotationView;
returnfitView;
}
returnnil;
}
此為正確方法堕仔,獲取超出super view的點(diǎn)擊事件躲因。