UIView animation using 90%CPU

2019-08-20 06:05发布

问题:

hi i have animation which loop but are using 90% of my iphone CPU processing and are heating up the phone. what have i done wrong ?

anybody can give me some advise ?

thanks

-(void)nextAnimation:(float)previousWidth {

//picture loop
imageViewTop.image = imageViewBottom.image;
imageViewBottom.image = [imageArray objectAtIndex:[imageArray count] - 1];

[imageArray insertObject:imageViewBottom.image atIndex:0];
[imageArray removeLastObject];
imageViewTop.alpha = 1.0;
imageViewBottom.alpha = 0.0;

[UIView animateWithDuration:4.0
                 animations:^{ 
                     imageViewTop.alpha = 0.0;
                     imageViewBottom.alpha = 1.0;
                     } 
                 completion:^(BOOL  completed){
                     [self nextAnimation:stringsize.width];
                 }
 ]; 

回答1:

You got a infinite loop in you code. You must have a quit condition to avoid infinite loop. A static counter is zero, and run one time add 1, if counter > n quit.