1

MKMapview在 IOS 应用程序中缩放/拖动时,IOS 6.0 是否比MKMapview在 5.1 中使用的内存更多ios5.0

mkmapview它在放大时给我内存警告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;
}

上面的viewForannotation委托方法代码mkmapView

4

2 回答 2

5

由于 6+ 地图视图使用矢量套件,因此在 4/5 中它使用谷歌地图

我必须告诉你,ios6+ 中的 MKMapView 真的很糟糕。我们花了数周时间让它消耗更少的内存,但新的矢量套件会疯狂地使用内存:/

展示整个世界——繁荣 50mb,展示 cupertino + 30,去 la + 30 去华盛顿特区 + 30 左右......

无事可做..哦,有些事情你可以尝试让它变得更好,但最终问题仍然存在。地图视图无法管理,我们切换到 google maps sdk。


我们在切换之前所做的事情(有帮助):

  • 我们在多个屏幕上共享一个地图视图。我们有一个 MKMapViewWrapperView 帮助很大,因为地图视图在释放时实际上会“泄漏”,所以我们总是保留它

  • 我们有时会切换 mapType... *这听起来很奇怪)导致地图视图释放一些内存

于 2013-03-29T11:11:22.953 回答
0

我已经确定内存泄漏发生时,当您设置MKmapview类型为混合时。发生了这种类型的内存泄漏。

我的建议只是选择卫星

于 2014-05-05T09:13:19.060 回答