加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – CALayerInvalidGeometry’,原因:’CALayer边界包含Na

发布时间:2020-12-15 02:00:29 所属栏目:百科 来源:网络整理
导读:我已经看了很多,但我只能看到与这个问题有关的webView和表。我的完全不同似乎有同样的崩溃例外: CALayerInvalidGeometry’,原因:’CALayer bounds包含NaN:[0 0;南南] 基本上我在这里是一个视图,使图像褪色和缩放??。我最近决定在UIView动画中使用CGAff
我已经看了很多,但我只能看到与这个问题有关的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);
    [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,3.86);

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

编辑:尝试这个

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

    imageView_A.frame = CGRectMake(300,attractLocs_y_A[attractLocs_A_index]);



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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读