1.在退出的時(shí)候及時(shí)釋放代理 viewwilldisappear的時(shí)候莹捡,delegate設(shè)置為nil
- (void)viewWillDisappear:(BOOL)animated {
[MAMapView shareMAMapView].showsUserLocation = NO;
[MAMapView shareMAMapView].delegate = nil;
[super viewWillDisappear:animated];
}
2.每次進(jìn)入地圖都會(huì)new一個(gè)mapview出來(lái)授艰。進(jìn)進(jìn)出出晌块,cpu飆升馍刮,用單例實(shí)現(xiàn)地圖
static MAMapView *_mapView = nil;
+ (MAMapView *)shareMAMapView {
@synchronized(self) {
[MAMapServices sharedServices].apiKey = kAMapSearchApplicationSecretKey;
if (_mapView == nil) {
CGRect frame = [[UIScreen mainScreen] bounds];
_mapView = [[MAMapView alloc] initWithFrame:frame];
_mapView.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_mapView.showsUserLocation = YES;
// _mapView.rotateEnabled = YES;
// _mapView.rotateCameraEnabled = YES;
_mapView.zoomEnabled = YES;
}
_mapView.frame = [UIScreen mainScreen].bounds;
return _mapView;
}
}
//重寫(xiě)allocWithZone保證分配內(nèi)存alloc相同
+ (id)allocWithZone:(NSZone *)zone {
@synchronized(self) {
if (_mapView == nil) {
_mapView = [super allocWithZone:zone];
return _mapView; // assignment and return on first allocation
}
}
return nil; // on subsequent allocation attempts return nil
}
//保證copy相同
+ (id)copyWithZone:(NSZone *)zone {
return _mapView;
}