增加大头针视图点击响应区域

网络请求回来的大头针视图的坐标、title、subtitle以及其他相关信息如何与指定的大头针视图绑定?
viewcontroller.m
- (void)viewDidLoad {
        // 网络请求返回的标注的模型数据
        DataM *dataM;
        CustomAnno *pointAnnotation = [[CustomAnno alloc] init];
        pointAnnotation.dataM = dataM;
        [self.mapView addAnnotation:pointAnnotation];
}


// 根据anntation生成对应的View
- (MAAnnotationView *)mapView:(MAMapView *)mapView viewForAnnotation:(id)annotation {
    if ([annotation isKindOfClass:[MAPointAnnotation class]]) {
        MAPinAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"reuseID"];
        if (annotationView == nil) {
            annotationView = [[MAPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"reuseID"];
        }
         CustomAnno *anno = (CustomAnno *)annotation;
        annotationView.image = [self getAnnotationViewNorImageWithAnno:anno];
        return annotationView;
    }
    return nil;
}

- (MAMapView *)mapView {
    if (!_mapView) {
        ///初始化地图
        _mapView = [[MAMapView alloc] initWithFrame:self.view.bounds];
        _mapView.delegate = self;
    }
    return _mapView;
}
.h

#import 
@class ListDataM;
@interface CustomAnno : MAPointAnnotation
/** model  */
@property (nonatomic, strong)  ListDataM *dataM;
@end

.m

#import "CustomAnno.h"
@implementation CustomAnno
- (void)setDataM:(ListDataM *)dataM {
        _dataM = dataM;
        NSNumber *latitude = dataM.latitude;
        NSNumber *longitude = dataM.longitude;
        self.coordinate = CLLocationCoordinate2DMake(latitude.doubleValue ,longitude.doubleValue );
        self..title = dataM.title;
        self..subtitle = dataM.subtitle];
}
@end

使用系统提供的MAPinAnnotationView生成的大头针视图的点击范围有限,如果赋值给image的图片太大,会出现点击图片大多区域,无法响应代理方法didSelectAnnotationView的bug;

解决方法是使用 系统提供的MAAnnotationView代替MAPinAnnotationView可以增大大头针视图的点击范围;

你可能感兴趣的:(增加大头针视图点击响应区域)