除了手动调整图像编辑软件中的PNG之外,有没有办法以编程方式简化此动画?即:显示一个easeOut效果。除非我使用错误的关键字搜索答案,否则我已经看过并且没有在网上看到答案。
NSMutableArray * images = [@[] mutableCopy];
for (int i = currentFrame; i <= maxFrame; i++) {
NSString * imageString = [NSString stringWithFormat:@"icon_introchart_%ld",i];
UIImage * newImage = [UIImage imageNamed:imageString];
[images addObject:newImage];
}
_introChart.animationImages = images;
_introChart.animationDuration = 2.0f;
_introChart.animationRepeatCount = 1;
已编辑 - &gt;但我仍然遗漏了一些东西:
CAKeyframeAnimation * animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
[animation setCalculationMode:kCAAnimationLinear];
animation.duration = 2.0;
animation.values = images;
animation.repeatCount = 1;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[animation setRemovedOnCompletion:YES];
[_introChart.layer addAnimation:animation forKey:@"contents"];
// _introChart.animationImages = images;
// _introChart.animationDuration = 2.0f;
//_introChart.animationRepeatCount = 1;
编辑:我需要提供CGImageRefs而不是UIImages用于&#34;内容&#34; ...现在可以使用。
UIImage * newImage = [UIImage imageNamed:imageString];
CGImageRef cgImage = [newImage CGImage];
[images addObject:(__bridge id)(cgImage)];
答案 0 :(得分:1)
简单的UIImage动画就是这么简单。你当然可以做你想做的事,但你必须使用真正的动画来获得你所要求的那种时间控制。最简单的方法可能是使用CAKeyframeAnimation,它可以控制动画“帧”的时间。