xcode CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 0; nan nan] 崩溃在望

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4867968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:41:29  来源:igfitidea点击:

CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 0; nan nan] crash in view

iphonexcodeipadanimationcrash

提问by Chewie The Chorkie

I've looked a lot into this, but I can only seem to get webView and tables relating to this issue. Mine's totally different it seems with the same crash exception:

我对此进行了很多研究,但似乎只能获得与此问题相关的 webView 和表格。我的完全不同,似乎有相同的崩溃异常:

CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 0; nan nan]

CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 0; 南南]

Basically what I have here is a view that fades and scales images. I've recently decided to change my code using CGAffineTransformScale in a UIView animation instead of scaling things up a notch every time a timer ticks. This uses way less processing power.

基本上我在这里是一个淡入淡出和缩放图像的视图。我最近决定在 UIView 动画中使用 CGAffineTransformScale 更改我的代码,而不是每次计时器滴答作响时将事情放大一个档次。这使用更少的处理能力。

But no matter what order I have the pictures in, it always crashes after the 19th one. It does not seem to be an issue with the positioning coordinate array that it refers to, because it is only 6 in length and loops over after it reaches its length. So for some reason now since I've implemented this animation code it gives me that crash. Anyone know why?

但不管我把图片放在什么顺序,它总是在第 19 个之后崩溃。它所指的定位坐标数组似乎不是问题,因为它的长度只有6,并且在达到其长度后循环。所以出于某种原因,自从我实现了这个动画代码后,它给了我那个崩溃。有谁知道为什么?

Here's the part I've changed since it started crashing:

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

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

EDIT:

编辑

Here's how I got the code above to work without the crashing problem using CGAffineTransformIdentity.

下面是我如何使用 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;}

采纳答案by Max

According to the stack trace the problem is here

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

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

Try to set the imageView_A.transform to identity. Another solution (and I think better) would be using the UIScrollView for scaling (it is also could be made animated).

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

Edit: try this

编辑:试试这个

    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];