CALayerInvalidGeometry',原因:'CALayer bounds包含NaN:[0 0;南楠]在视野中崩溃

时间:2011-02-01 21:09:02

标签: iphone xcode ipad animation crash

我已经看了很多,但我似乎只能获得与此问题相关的webView和表格。我的完全不同似乎与同样的崩溃异常:

CALayerInvalidGeometry',原因:'CALayer bounds包含NaN:[0 0;南楠]

基本上我在这里有一个视图,可以淡化和缩放图像。我最近决定在UIView动画中使用CGAffineTransformScale更改我的代码,而不是每次计时器滴答时都缩放一个档次。这使用较少的处理能力。

但无论我有什么顺序,它都会在第19局之后崩溃。它所引用的定位坐标数组似乎不是问题,因为它只有6个长度,并在达到其长度后循环。所以出于某些原因,因为我已经实现了这个动画代码,它让我崩溃了。谁知道为什么?

这是我自开始崩溃以来所改变的部分:

-(void) onTimer{

if(scaleTimer_A==5){

    imageView_A.image = [UIImage imageNamed:[attractList_A objectAtIndex:imageIndex_A]];

    imageView_A.frame = CGRectMake(300, 200, 3.86, 3.86);

    imageView_A.center = CGPointMake(attractLocs_x_A[attractLocs_A_index], attractLocs_y_A[attractLocs_A_index]);



    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:2];
    imageView_A.alpha = 1;
    imageView_A.transform = CGAffineTransformScale(imageView_A.transform, 100, 100);
    [UIView commitAnimations]; 
}

if(scaleTimer_A==10){

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.75];
    imageView_A.alpha = 0;
    imageView_A.transform = CGAffineTransformScale(imageView_A.transform, 1.2, 1.2);
    [UIView commitAnimations]; 

    scaleTimer_A=0;

    imageIndex_A+=1;

    if(imageIndex_A==imageIndex_A_size){
        imageIndex_A=0;
    }

    attractLocs_A_index+=1;

    if(attractLocs_A_index==attractLocs_A_SIZE){
        NSLog(@"Back to zero A");
        attractLocs_A_index=0;
    }
    NSLog(@"Image A =%@", [attractList_A objectAtIndex:imageIndex_A]);
}

scaleTimer_A+=1;}

修改

以下是我如何使用CGAffineTransformIdentity在没有崩溃问题的情况下使用上面的代码。

-(void) onTimer{

if(scaleTimer_A==5){

    imageView_A.image = [UIImage imageNamed:[attractList_A objectAtIndex:imageIndex_A]];

    imageView_A.transform = CGAffineTransformIdentity;

    imageView_A.center = CGPointMake(attractLocs_x_A[attractLocs_A_index], attractLocs_y_A[attractLocs_A_index]);



    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:2];
    imageView_A.alpha = 1;
    imageView_A.transform = CGAffineTransformScale(CGAffineTransformIdentity, 100, 100);
    [UIView commitAnimations]; 
}

if(scaleTimer_A==10){

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:.75];
    imageView_A.alpha = 0;
    imageView_A.transform = CGAffineTransformScale(CGAffineTransformIdentity, 120, 120);
    [UIView commitAnimations]; 

    scaleTimer_A=0;

    imageIndex_A+=1;

    if(imageIndex_A==imageIndex_A_size){
        imageIndex_A=0;
    }

    attractLocs_A_index+=1;

    if(attractLocs_A_index==attractLocs_A_SIZE){
        NSLog(@"Back to zero A");
        attractLocs_A_index=0;
    }
    NSLog(@"Image A =%@", [attractList_A objectAtIndex:imageIndex_A]);
}

scaleTimer_A+=1;}

1 个答案:

答案 0 :(得分:10)

根据堆栈跟踪问题在这里

imageView_A.frame = CGRectMake(300, 200, 3.86, 3.86);

尝试将imageView_A.transform设置为identity。另一个解决方案(我认为更好)将使用UIScrollView进行缩放(也可以制作动画)。

编辑:试试这个

    imageView_A.image = [UIImage imageNamed:[attractList_A objectAtIndex:imageIndex_A]];

    imageView_A.frame = CGRectMake(300, 200, 3.86, 3.86);

    imageView_A.center = CGPointMake(attractLocs_x_A[attractLocs_A_index], attractLocs_y_A[attractLocs_A_index]);



    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:2];
    imageView_A.alpha = 1;
    imageView_A.frame = CGRectMake(300, 200, 386.0f, 386.0f);
    [UIView commitAnimations];