iphone - CALayerInvalidGeometry',原因: 'CALayer bounds contains NaN: [0 0; nan nan] crash in view

标签 iphone xcode ipad animation crash

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

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

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

最佳答案

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

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

关于iphone - CALayerInvalidGeometry',原因: 'CALayer bounds contains NaN: [0 0; nan nan] crash in view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4867968/

相关文章:

iphone - 自动观察 UITableView 中的文件系统变化

ios - 尝试在 swiftui 中给边框一个圆角半径

ios - 分发配置文件是否来自分发证书?

iphone - Storyboard可以封装吗?

iphone - LazyTableImages for iPhone 示例代码重新加载问题

iphone - iOS SDK 编辑 PDF 添加图像

iOS 9.2 常规设置中缺少配置文件部分

ios - 使用(FaSTLane-)脚本更改 "App Icon Source"(不是 Info.plist)中的 "Target > General"

ios - (空)libc++abi.dylib : terminate called throwing an exception

html - 带有 SVG 标志的 CSS 三 Angular 形剪辑路径未在平板电脑/iPad 中显示