问题描述
ios 6.0在ios app中缩放/拖动时是否需要更多内存用于MKMapview,而不是ios5.0或5.1中使用的MKMapview?
Is ios 6.0 takes more memory for MKMapview while zooming/dragging in ios app, than MKMapview used in ios5.0 or 5.1?
它给我内存警告在ios6.0中缩放mkmapview
It give me memory warning while zooming mkmapview in ios6.0
- (MKAnnotationView *)mapView:(MKMapView *)mapView1 viewForAnnotation:(id <MKAnnotation> )annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
((MKUserLocation *)annotation).title = kCurrentLocation;
return nil;
}
if (annotation == self.calloutAnnotation)
{
CalloutMapAnnotationView *calloutMapAnnotationView=nil;
if (calloutMapAnnotationView==nil){
calloutMapAnnotationView = (CalloutMapAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"CalloutAnnotation"];
calloutMapAnnotationView = [[CalloutMapAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"CalloutAnnotation"];
UIImageView *calloutImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,285,109)];
calloutImageView.image = [UIImage loadImageFromBundle:@"map-pop"];
[calloutMapAnnotationView addSubview:calloutImageView];
[calloutImageView bringSubviewToFront:calloutMapAnnotationView];
CGRect frame1,btnframe,btnframe2;
int font1;
frame1 = CGRectMake(14,10,270,35);
//frame for subitle label of map annotation view.
btnframe = CGRectMake(12,53,80,25);
btnframe2= CGRectMake(btnframe.size.width+20,btnframe.origin.y,btnframe.size.width+35, btnframe.size.height);
font1 = 14.0;
calloutMapAnnotationView.calloutTitleLabel=nil;
calloutMapAnnotationView.calloutTitleLabel = [[UILabel alloc]initWithFrame:frame1];
calloutMapAnnotationView.calloutTitleLabel.numberOfLines = 2;
calloutMapAnnotationView.calloutTitleLabel.layer.cornerRadius=6;
[calloutMapAnnotationView.calloutTitleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:font1]];
[calloutMapAnnotationView.calloutTitleLabel setBackgroundColor:[UIColor clearColor]];
[calloutMapAnnotationView.calloutTitleLabel setTextColor:[UIColor whiteColor]];
calloutMapAnnotationView.infoButton = [UIButton buttonWithType:UIButtonTypeCustom];
[calloutMapAnnotationView.infoButton setBackgroundImage:[UIImage loadImageFromBundle:@"blank-btn"] forState:UIControlStateNormal];
[calloutMapAnnotationView.infoButton setTitle:kInfo forState:UIControlStateNormal];
[[calloutMapAnnotationView.infoButton titleLabel ]setFont:[UIFont fontWithName:@"Helvetica-Bold" size:font1-1]];
[calloutMapAnnotationView.infoButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
calloutMapAnnotationView.infoButton.frame = btnframe;
calloutMapAnnotationView.infoButton.exclusiveTouch = YES;
[calloutMapAnnotationView.infoButton addTarget:self action:@selector(buttonPressedAction:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchCancel];
[calloutMapAnnotationView addSubview:calloutMapAnnotationView.infoButton];
[calloutMapAnnotationView.infoButton bringSubviewToFront:calloutMapAnnotationView];
[calloutMapAnnotationView addSubview:calloutMapAnnotationView.calloutTitleLabel];
// infoButton=nil;
calloutMapAnnotationView.routeButton = [UIButton buttonWithType:UIButtonTypeCustom];//inDark
[calloutMapAnnotationView.routeButton setBackgroundImage:[UIImage loadImageFromBundle:@"blank-btn"] forState:UIControlStateNormal];
calloutMapAnnotationView.routeButton.frame = btnframe2;
[calloutMapAnnotationView.routeButton setTitle:kRouteDraw forState:UIControlStateNormal];
[[calloutMapAnnotationView.routeButton titleLabel ]setFont:[UIFont fontWithName:@"Helvetica-Bold" size:font1-1]];
[calloutMapAnnotationView.routeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
calloutMapAnnotationView.routeButton.exclusiveTouch = YES;
calloutMapAnnotationView.routeButton.tag = well_ID;
[calloutMapAnnotationView.routeButton addTarget:self action:@selector(showRouteView:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchCancel];
[calloutMapAnnotationView addSubview:calloutMapAnnotationView.routeButton];
}
calloutMapAnnotationView.calloutTitleLabel.text = self.titleStr;
NSLog(@"well id---%d",well_ID);
calloutMapAnnotationView.infoButton.tag = well_ID;
int locationId=[[resultDict objectForKey:@"uid"] intValue];
if(well_ID!=locationId)
{
calloutMapAnnotationView.routeButton.hidden = NO;
calloutMapAnnotationView.routeButton.tag = well_ID;
[calloutMapAnnotationView.routeButton bringSubviewToFront:calloutMapAnnotationView];
}else{
calloutMapAnnotationView.routeButton.hidden = YES;
}
calloutMapAnnotationView.parentAnnotationView = self.selectedAnnotationView;
calloutMapAnnotationView.mapView = mapView;
return calloutMapAnnotationView;
} else {
static NSString *defaultPinID = @"Pin";
MKAnnotationView* pin = (MKAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier: defaultPinID];
int annotationValue =[annotation_array indexOfObject:annotation];
NSString * searchLocationTitle= [annotation title];
if ( pin == nil ) {
pin = (MKAnnotationView*) [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: defaultPinID];
pin.image = [UIImage loadImageFromBundle:@"logo"];
}
pin.canShowCallout = NO;
if (annotationValue!=0) {
if([searchLocationTitle isEqualToString:kCurrentLocation])
{
pin.image=nil;
}
else if([searchLocationTitle isEqualToString:kSearchedLocation])
{
pin.image=nil;
}
else
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
pin.frame = CGRectMake(-15, 0, 40,65);
} else
{
pin.frame = CGRectMake(-15, 0, 45,70);
}
}
}
else{
return nil;
}
return pin;
}
return nil;
}
mkmapView的viewForannotation委托方法的上述代码。
Above code for viewForannotation delegate method of mkmapView.
推荐答案
因为6个以上的地图视图使用矢量工具包,在4/5中它使用谷歌地图
我必须告诉你,ios6 +中的MKMapView非常糟糕。我们花了WEEKS来消耗更少的内存,但是新的矢量套件使用了疯狂的内存:/
since 6+ map views use vector kit, in 4/5 it uses google maps
I must tell you that the MKMapView in ios6+ is really really bad. we spent WEEKS getting it to consume less memory but the new vector kit uses memory like crazy :/
显示整个世界 - 热潮50mb,显示cupertino + 30,go到la + 30去华盛顿DC + 30左右...
show the whole world -- boom 50mb, show cupertino + 30, go to la + 30 go to washington DC + 30 or so...
什么都没有...哦,你可以尝试让它变得更好,但问题仍然存在。 地图视图无法管理,我们切换到google地图sdk。
nothing todo.. oh there's things you can try to make it better but uulimately the problem remains. The map view is unmanageable and we switched to the google maps sdk.
-
我们在多个屏幕上共享一个地图视图。我们有一个MKMapViewWrapperView
帮助了很多,因为地图视图在解除分配时实际上泄漏,所以我们总是保留它
we shared one map view across multiple screens. We had a MKMapViewWrapperViewthat helped a lot because a map view actually 'leaks' when it is deallocated, so we always kept it around
我们有时切换mapType ... *听起来很奇怪)导致地图视图释放一些内存
we sometimes toggled the mapType... that *it sounds weird) causes the map view to free some of its memory
这篇关于iOS 6.0或更高版本中的MKMapView内存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!