关于高德地图的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];
上一篇下一篇

猜你喜欢

热点阅读