Я анимирую изображения с помощью UIImageView:
imageView.animationImages = [NSArray arrayWithArray:imgNameArr];
imageView.animationDuration = 2;
imageView.animationRepeatCount = 0;
[imageView startAnimating];
В какой-то момент позже я пытаюсь изменить изображения на новые:
[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];
Это НЕ работает. Мое приложение либо вылетает, либо изображения исчезают. Я видел, что у некоторых людей есть такая же проблема, и они создают различные обходные пути. Что-то не так с моим кодом? Можно ли что-то сделать?
Кроме того, я обнаружил, что с этим кодом объект исчезает в конце анимации.
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];