最近做了一个关于地图位置的demo 效果图
点击事件在annotationView 上 其中 小车上方的两个按钮要想实现触摸事件 他们的fream要在 annotationView中 解决方法 代码如下
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// if (![annotation isMemberOfClass:[WXAnnotation class]]) {
// return nil;
// }
static NSString *identifier = @"kAnnotationView";
LCAnnotationView *annotationView = (LCAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!annotationView) {
annotationView = [[LCAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
//是否显示标注视图的按钮
annotationView.canShowCallout = YES;
//自定义标注视图背景
//annotationView.image = [UIImage imageNamed:@"car-take_car"];
annotationView.frame = CGRectMake(0,0, 220, 200);
annotationView.userInteractionEnabled = YES;
//设置标注视图可点击的按钮
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
// 问题解决
annotationView.annotation = annotation;
return annotationView;
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
if (!pinView) {
pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
//是否显示从天而降的动画
pinView.animatesDrop = YES;
pinView.pinColor = MKPinAnnotationColorPurple;
}
return pinView;
}