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; nan nan]
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.
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;}
EDIT:
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);
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).
Edit: try this
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];