CoreAnimation: не удалось выделить 1971232 байта для моих приложений iPad?


Я использую основную работу фрейма графика, я обновляю вид через некоторое время я получил ошибку для "CoreAnimation: не удалось выделить 1971232 байта". здесь я прилагаю свой код для построения чата

- (void)ipadDraw
{
    CPTGradient *overlayGradient = [[[CPTGradient alloc] init] autorelease];
    overlayGradient.gradientType = CPTGradientTypeRadial;
    overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.0] atPosition:0.0];
    overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.5] atPosition:0.9];
    overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.8] atPosition:1.0];
    CGRect rect=self.view.bounds;


    if(currentOrientation   == UIInterfaceOrientationPortrait || currentOrientation== UIInterfaceOrientationPortraitUpsideDown)
    {

        NSLog(@"%@",NSStringFromCGRect(rect));
        rect.size.width = rect.size.width;
        rect.origin.x=0;
        rect.origin.y-=120;
    }
    else 
    {
        NSLog(@"%@",NSStringFromCGRect(rect));

        rect.origin.x=60;
        rect.origin.y+=25;
        rect.size.width=600;
        rect.size.height=700;
    }




    defaultLayerHostingView = [(CPTGraphHostingView *)[CPTGraphHostingView alloc] initWithFrame:rect];
      defaultLayerHostingView.userInteractionEnabled=YES;
    defaultLayerHostingView.exclusiveTouch=YES;
    defaultLayerHostingView.multipleTouchEnabled=YES;
    defaultLayerHostingView.backgroundColor= [UIColor clearColor];
    //defaultLayerHostingView.delegate=self;

    [myScrollView addSubview:defaultLayerHostingView];
    myScrollView.delegate=self;


    CGRect bounds  = defaultLayerHostingView.bounds;
    graph  = [[CPTXYGraph alloc] initWithFrame:[defaultLayerHostingView bounds]];

    defaultLayerHostingView.hostedGraph = graph; 

    CPTMutableTextStyle *textStyle  = [CPTMutableTextStyle textStyle];//
    textStyle.color = [CPTColor grayColor];
    textStyle.fontName = @"Helvetica-Bold";
    textStyle.fontSize = bounds.size.height / 20.0f;
    graph.titleTextStyle = textStyle;
    graph.titleDisplacement = CGPointMake(0.0f, bounds.size.height / 18.0f);
    graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
    graph.plotAreaFrame.masksToBorder = NO;

    // Graph padding
    CGFloat boundsPadding = bounds.size.width / 20.0f;
    NSLog(@"the bounds padding is %f",boundsPadding);
    graph.paddingLeft = boundsPadding;
    graph.paddingTop = graph.titleDisplacement.y * 2;
    graph.paddingRight = 32;
    graph.paddingBottom = boundsPadding;
    graph.axisSet = nil;

    // Add pie chart

     CPTPieChart *piePlot = [[CPTPieChart alloc] init];

    piePlot.dataSource = self;
    piePlot.title=@"First";


    piePlot.pieRadius=200;
    piePlot.startAngle = M_PI_4;
    piePlot.sliceDirection = CPTPieDirectionCounterClockwise;
    piePlot.overlayFill = [CPTFill fillWithGradient:overlayGradient];
    piePlot.delegate = self;
    [graph addPlot:piePlot];

    [piePlot release];

    CPTLegend *theLegend = [CPTLegend legendWithGraph:graph];
    theLegend.numberOfColumns = 2;
    theLegend.fill = [CPTFill fillWithColor:(CPTColor *)[UIColor clearColor]];
    theLegend.cornerRadius = 5.0;
    theLegend.swatchSize=CGSizeMake(25, 25);
    theLegend.textStyle=textStyle1;
    graph.legend = theLegend;
    graph.legendAnchor =CPTRectAnchorCenter;


    graph.legendDisplacement=CGPointMake(-10, -275);

    UIButton *ProceedButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [ProceedButton setImage:[UIImage imageNamed:@"details_button_land.png"] forState:UIControlStateNormal];
    [ProceedButton setUserInteractionEnabled:YES];

    [myScrollView  addSubview:claimsProceedButton];
    ProceedButton.tag=0;
    if(currentOrientation   == UIInterfaceOrientationPortrait || currentOrientation== UIInterfaceOrientationPortraitUpsideDown)
    {


        [ProceedButton setFrame:CGRectMake((myScrollView.frame.size.width-300)/2, 720, 300.00 , 51.00)];
    }
    else{
        [ProceedButton setFrame:CGRectMake((myScrollView.frame.size.width-300)/2, 690, 300.00 , 51.00)];
    }


    rect=self.view.bounds;
    [ProceedButton addTarget:self action:@selector(ProceedDetail:) forControlEvents:UIControlEventTouchUpInside];
    UILabel *viewDetails = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300.00, 51.00)];
    [ProceedButton addSubview:viewDetails];
    [viewDetails setText:@"View Chart Data"];
    [viewDetails setFont:[UIFont boldSystemFontOfSize:13]];
    [viewDetails setBackgroundColor:[UIColor clearColor]];
    [viewDetails setTextAlignment:UITextAlignmentCenter];

    NSLog(@"%@",NSStringFromCGRect(rect));

    rect=self.view.bounds;

    defaultLayerHostingView=nil;

}
2 2

2 ответа:

Вы можете заменить существующий код на этот

    - (void)ipadDraw

{

CPTGradient *overlayGradient = [[[CPTGradient alloc] init] autorelease];
overlayGradient.gradientType = CPTGradientTypeRadial;
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.0] atPosition:0.0];
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor]
overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.5] atPosition:0.9];
enter code here   overlayGradient = [overlayGradient addColorStop:[[CPTColor blackColor] colorWithAlphaComponent:0.8] atPosition:1.0];

CGRect rect=self.view.bounds;if(currentOrientation==UIInterfaceOrientationPortrait || currentOrientation== UIInterfaceOrientationPortraitUpsideDown)
  { NSLog(@"%@",NSStringFromCGRect(rect));



rect.size.width = rect.size.width;
rect.origin.x=0;
rect.origin.y-=120;
}

else { 
 NSLog(@"%@",NSStringFromCGRect(rect)); 
rect.origin.x=60;
rect.origin.y+=25;
rect.size.width=600;
rect.size.height=700;
}

defaultLayerHostingView = [[(CPTGraphHostingView *)[CPTGraphHostingView alloc] initWithFrame:rect]autorelease];
defaultLayerHostingView.userInteractionEnabled=YES;
defaultLayerHostingView.exclusiveTouch=YES;
defaultLayerHostingView.multipleTouchEnabled=YES;
defaultLayerHostingView.backgroundColor= [UIColor clearColor];
[myScrollView addSubview:defaultLayerHostingView];
myScrollView.delegate=self;
CGRect bounds  = defaultLayerHostingView.bounds;
graph  = [[[CPTXYGraph alloc] initWithFrame:[defaultLayerHostingView bounds]]autorlease];
defaultLayerHostingView.hostedGraph = graph; 

CPTMutableTextStyle *textStyle  = [CPTMutableTextStyle textStyle];//
textStyle.color = [CPTColor grayColor];
textStyle.fontName = @"Helvetica-Bold";
textStyle.fontSize = bounds.size.height / 20.0f;
graph.titleTextStyle = textStyle;
graph.titleDisplacement = CGPointMake(0.0f, bounds.size.height / 18.0f);
graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
graph.plotAreaFrame.masksToBorder = NO;

// Graph padding
CGFloat boundsPadding = bounds.size.width / 20.0f;
NSLog(@"the bounds padding is %f",boundsPadding);
graph.paddingLeft = boundsPadding;
graph.paddingTop = graph.titleDisplacement.y * 2;
graph.paddingRight = 32;
graph.paddingBottom = boundsPadding;
graph.axisSet = nil;

// Add pie chart

 CPTPieChart *piePlot = [[[CPTPieChart alloc] init]autorelease];

piePlot.dataSource = self;
piePlot.title=@"First";


piePlot.pieRadius=200;
piePlot.startAngle = M_PI_4;
piePlot.sliceDirection = CPTPieDirectionCounterClockwise;
piePlot.overlayFill = [CPTFill fillWithGradient:overlayGradient];
piePlot.delegate = self;
[graph addPlot:piePlot];

[piePlot release];

CPTLegend *theLegend = [CPTLegend legendWithGraph:graph]autorlease];
theLegend.numberOfColumns = 2;
theLegend.fill = [CPTFill fillWithColor:(CPTColor *)[UIColor clearColor]];
theLegend.cornerRadius = 5.0;
theLegend.swatchSize=CGSizeMake(25, 25);
theLegend.textStyle=textStyle1;
graph.legend = theLegend;
graph.legendAnchor =CPTRectAnchorCenter;


graph.legendDisplacement=CGPointMake(-10, -275);

UIButton *ProceedButton = [[UIButton buttonWithType:UIButtonTypeCustom];
[ProceedButton setImage:[UIImage imageNamed:@"details_button_land.png"] forState:UIControlStateNormal]autorelease];
[ProceedButton setUserInteractionEnabled:YES];

[myScrollView  addSubview:claimsProceedButton];
ProceedButton.tag=0;
if(currentOrientation   == UIInterfaceOrientationPortrait || currentOrientation== UIInterfaceOrientationPortraitUpsideDown)
{


    [ProceedButton setFrame:CGRectMake((myScrollView.frame.size.width-300)/2, 720, 300.00 , 51.00)];
}
else{
    [ProceedButton setFrame:CGRectMake((myScrollView.frame.size.width-300)/2, 690, 300.00 , 51.00)];
}


rect=self.view.bounds;
[ProceedButton addTarget:self action:@selector(ProceedDetail:) forControlEvents:UIControlEventTouchUpInside];
UILabel *viewDetails = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300.00, 51.00)];
[ProceedButton addSubview:viewDetails];
[viewDetails setText:@"View Chart Data"];
[viewDetails setFont:[UIFont boldSystemFontOfSize:13]];
[viewDetails setBackgroundColor:[UIColor clearColor]];
[viewDetails setTextAlignment:UITextAlignmentCenter];

NSLog(@"%@",NSStringFromCGRect(rect));

rect=self.view.bounds;

defaultLayerHostingView=nil;

}

Можно выполнить авторелиз при инициализации объекта