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

编程入门 行业动态 更新时间:2024-10-16 22:22:46
本文介绍了CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 0;nan nan] 崩溃在望的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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:

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

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

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

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.

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

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?

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

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

编辑:

以下是我如何使用 CGAffineTransformIdentity 使上述代码正常工作而不会出现崩溃问题.

Here's how I got the code above to work without the crashing problem using 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;}

推荐答案

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

According to the stack trace the problem is here

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

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

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

这篇关于CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 0;nan nan] 崩溃在望的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 01:15:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/993794.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:reason   CALayerInvalidGeometry   CALayer   nan   NaN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!