Iphone CALayerInvalidGeometry';,原因:';CALayer边界在视图中包含NaN:[0;NaN NaN]崩溃

Iphone CALayerInvalidGeometry';,原因:';CALayer边界在视图中包含NaN:[0;NaN NaN]崩溃,iphone,xcode,ipad,animation,crash,Iphone,Xcode,Ipad,Animation,Crash,我对此做了很多研究,但似乎只能得到与此问题相关的webView和表。我的完全不同,似乎有相同的崩溃例外: CALayerInvalidGeometry',原因:'CALayer边界包含NaN:[0;NaN NaN] 基本上我这里有一个淡入淡出和缩放图像的视图。我最近决定在UIView动画中使用CGAffineTransformScale来更改代码,而不是每次定时器滴答作响时都将代码放大一个等级。这使用更少的处理能力 但不管我把照片按什么顺序排列,它总是在第19张照片之后崩溃。它所指的定位坐标阵列

我对此做了很多研究,但似乎只能得到与此问题相关的webView和表。我的完全不同,似乎有相同的崩溃例外:

CALayerInvalidGeometry',原因:'CALayer边界包含NaN:[0;NaN NaN]

基本上我这里有一个淡入淡出和缩放图像的视图。我最近决定在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;}
编辑

下面是我如何使用CGAffineTransformity使上面的代码工作而不出现崩溃问题

-(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;}

根据堆栈跟踪,问题就在这里

imageView_A.frame = CGRectMake(300, 200, 3.86, 3.86);
尝试将imageView\u 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]; 

NaN通常在除以零时出现。仔细检查一下你的数学。我也听说过,但我在代码中的什么地方除以0?你能发布堆栈跟踪吗?废话。。对不起,那是完全错误的日志。。暂停**由于未捕获异常“CALayerInvalidGeometry”而终止应用程序,原因:“CALayer边界包含NaN:[0;NaN NaN]”***第一次抛出时调用堆栈:(0 CoreFoundation 0x009ddbe9异常预处理+1851 libobjc.A.dylib 0x015 a15c2 objc异常抛出+47 2 CoreFoundation 0x00996628+[NSException提升:格式:参数:+136 3 CoreFoundation 0x0099659a+[NSException提升:格式:]+58 4 QuartzCore 0x0079a3ee_zl16CalayerSetBoundsP7CalayerKN2Ca4RectEB+227在我的情况下,将imageView_A.Transformation设置为CGAffineTransformity是不等效的。UIScrollView对我来说没有多大意义,特别是如果我希望多个图像视图独立转换。为什么imageVi的框架ew_A无论如何都可能是个问题?因为崩溃发生在imageView_A.FrameOK的设置过程中。谢谢。它似乎已经停止了崩溃。我只需要找出一个解决办法来调整它,使其表现出应有的样子。@Max我如何将CGAffineTransformity与我拥有的代码一起使用,并使其表现出相同的方式?我已经尝试了很多方法。我被难住了。好吧,试着像这样缩放视图。视图_A.transform=CGAffineTransformScale(CGAffineTransformIdentity,100100);但我不确定它是否会像预期的那样工作,因为我实际上不知道您想要达到什么最终结果。