gpt4 book ai didi

iphone - UIImageView 动画图像无法更改?

转载 作者:行者123 更新时间:2023-12-03 21:18:40 25 4
gpt4 key购买 nike

我正在使用 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];

最佳答案

由于animationImages是一个属性,因此您不需要将其设置为nil,并且在将其设置为nil后释放它不会执行任何操作(它将发送release到nil)。提前释放它会导致崩溃。只需将其设置为新值或为零。您不应该释放另一个对象的属性。

关于iphone - UIImageView 动画图像无法更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7265841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com