【发布时间】:2011-06-19 13:44:05
【问题描述】:
我对此进行了很多研究,但我似乎只能获得与此问题相关的 webView 和表格。我的完全不同,似乎有相同的崩溃异常:
CALayerInvalidGeometry', reason: 'CALayer bounds contains 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, 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;}
【问题讨论】:
-
NaN 通常在除以零时发生。仔细检查你所有的数学。
-
我也听说过,但是这段代码我在哪里除以 0?
-
你能发布堆栈跟踪吗?
-
废话.. 抱歉,这完全是错误的日志.. 等等
-
** 由于未捕获的异常“CALayerInvalidGeometry”而终止应用程序,原因:“CALayer bounds contains NaN: [0 0; nan nan]' *** 第一次抛出调用堆栈:( 0 CoreFoundation 0x009ddbe9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x015a15c2 objc_exception_throw + 47 2 CoreFoundation 0x00996628 +[NSException raise:format:arguments:] + 136 3 CoreFoundation 0x0099659a +[ NSException raise:format:] + 58 4 QuartzCore 0x0079a3ee _ZL16CALayerSetBoundsP7CALayerRKN2CA4RectEb + 227
标签: iphone xcode ipad animation crash