首先请原谅一个可能没有问题的人! 我是客观C的全新人物!
我想动画图像,动画结束时应显示动画“dymchart20.png”的最后一张图像。 我怎么能这样做?
这是我的动画代码:
aniChartView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"dymchart01.png"],
[UIImage imageNamed:@"dymchart02.png"],
[UIImage imageNamed:@"dymchart03.png"],
[UIImage imageNamed:@"dymchart04.png"],
[UIImage imageNamed:@"dymchart05.png"],
[UIImage imageNamed:@"dymchart06.png"],
[UIImage imageNamed:@"dymchart07.png"],
[UIImage imageNamed:@"dymchart08.png"],
[UIImage imageNamed:@"dymchart09.png"],
[UIImage imageNamed:@"dymchart10.png"],
[UIImage imageNamed:@"dymchart11.png"],
[UIImage imageNamed:@"dymchart12.png"],
[UIImage imageNamed:@"dymchart13.png"],
[UIImage imageNamed:@"dymchart14.png"],
[UIImage imageNamed:@"dymchart15.png"],
[UIImage imageNamed:@"dymchart16.png"],
[UIImage imageNamed:@"dymchart17.png"],
[UIImage imageNamed:@"dymchart18.png"],
[UIImage imageNamed:@"dymchart19.png"],
[UIImage imageNamed:@"dymchart20.png"],nil];
// all frames will execute in 3 seconds
aniChartView.animationDuration = 0.8;
// repeat the annimation forever
aniChartView.animationRepeatCount = 1;
// start animating
[aniChartView startAnimating];
感谢您的帮助!!!
答案 0 :(得分:0)
动画不会更改其动画元素的状态。这意味着如果您的uiview具有背景图像,则一旦动画停止,该图像将是相同的。 对于使用动画进行颜色更改或使用任何其他属性进行动画处理也是如此。 为了实现您的目标,您必须在动画结束后显式调用UIImage的更改为您想要查看的更改。 :)
这是一个您可能会发现有用的解决方案https://stackoverflow.com/a/7773141/1306884
答案 1 :(得分:0)
您可以使用NSTimer并将aniChartView声明为您的类的属性,如下所示:
@interface ViewController ()
@property (nonatomic, strong) UIImageView *aniChartView;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)beginAnimation {
self.aniChartView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"dymchart01.png"],
[UIImage imageNamed:@"dymchart02.png"],
[UIImage imageNamed:@"dymchart03.png"],
[UIImage imageNamed:@"dymchart04.png"],
[UIImage imageNamed:@"dymchart05.png"],
[UIImage imageNamed:@"dymchart06.png"],
[UIImage imageNamed:@"dymchart07.png"],
[UIImage imageNamed:@"dymchart08.png"],
[UIImage imageNamed:@"dymchart09.png"],
[UIImage imageNamed:@"dymchart10.png"],
[UIImage imageNamed:@"dymchart11.png"],
[UIImage imageNamed:@"dymchart12.png"],
[UIImage imageNamed:@"dymchart13.png"],
[UIImage imageNamed:@"dymchart14.png"],
[UIImage imageNamed:@"dymchart15.png"],
[UIImage imageNamed:@"dymchart16.png"],
[UIImage imageNamed:@"dymchart17.png"],
[UIImage imageNamed:@"dymchart18.png"],
[UIImage imageNamed:@"dymchart19.png"],
[UIImage imageNamed:@"dymchart20.png"],nil];
// all frames will execute in 3 seconds
self.aniChartView.animationDuration = 0.8;
// repeat the annimation forever
self.aniChartView.animationRepeatCount = 1;
// start animating
[self.aniChartView startAnimating];
[NSTimer scheduledTimerWithTimeInterval:0.8 target:self selector:@selector(staticImage) userInfo:nil repeats:NO];
}
-(void)staticImage {
[self.aniChartView stopAnimating];
[self.aniChartView setImage:[UIImage imageNamed:@"dymchart20.png"]];
}
@end