关于高德地图的MAMapView踩坑
2018-03-20 本文已影响434人
Benster
关于高德地图的MAMapView踩坑
在使用高德地图的MAMapView
地图的时候碰到无法设置size
的情况:
self.mapView = [[MAMapView alloc] initWithSize:CGSizeMake(100, 100)];
self.mapView.delegate = self;
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.mapView];
地图会自动适应self.view
,后来才发现MAMapView
会自适应SuperView
,所以在需要自己再加一层View
:
UIView *mapContentView = [[UIView alloc] initWithFrame:CGRectMake(15.f, 10.f, 300, 300)];
[self.view addSubview:mapContentView];
self.mapView = [[MAMapView alloc] initWithSize:mapContentView.size];
self.mapView.delegate = self;
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[mapContentView addSubview:self.mapView];