これについていろいろ調べてみましたが、この問題に関連するのは WebView とテーブルだけみたいです。私の場合はまったく違うようですが、クラッシュ例外は同じです:
CALayerInvalidGeometry'、理由: 'CALayer 境界に NaN が含まれています: [0 0; nan nan]
基本的に、ここにあるのは、画像をフェードアウトして拡大縮小するビューです。最近、タイマーが刻むたびにスケールを 1 段階上げるのではなく、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;}
ベストアンサー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];