I am animating images with UIImageView:
imageView.animationImages = [NSArray arrayWithArray:imgNameArr];
imageView.animationDuration = 2;
imageView.animationRepeatCount = 0;
[imageView startAnimating];
At some point later I am trying to change images to some new ones:
[imageView stopAnimating];
imageView.animationImages = nil;
[imageView.animationImages release];
imageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
nil];
[imageView setAnimationDuration:1];
[imageView startAnimating];
This does NOT work. My app either crashes or images disappear. I've seen a few people have the same problem and they create various workaround. Is something wrong with my code? Can something be done?
In addition I discovered that with this code below the object disappears at end of animation.
int x = rect.origin.x;
int y = rect.origin.y;
int w = rect.size.width;
float _frequency = 0;
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.duration = speed;
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
CGMutablePathRef pointPath = CGPathCreateMutable();
CGPathMoveToPoint(pointPath, NULL, rect.origin.x, rect.origin.y);
do {
CGFloat yVal = sin (_frequency * M_PI/180);
CGPathAddLineToPoint(pointPath, NULL, x, y + yVal * 15);
_frequency += freq;
x--;
} while (x > w);//does not go outside
pathAnimation.path = pointPath;
CGPathRelease(pointPath);
[imageView.layer addAnimation:pathAnimation forKey:@"pathAnimation"];
[imageView release];