如何参数化UIView动画?
我有很多这样的 case 语句,它们会触发各种 UIView 动画。我想编写一个模块并对它们进行参数化,这样我就不必一遍又一遍地重复类似的代码。为animationRepeatCount 和animationRepeatCount 传递(参数化)值的最佳方法是什么?动画持续时间?
case 10: //Animation Number 10
//.........
imageAnimation2.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"monkey_dancing_01.png"],
[UIImage imageNamed:@"monkey_dancing_02.png"],
[UIImage imageNamed:@"monkey_dancing_03.png"],
[UIImage imageNamed:@"monkey_dancing_04.png"],
nil];
imageAnimation2.animationRepeatCount = 4;
imageAnimation2.animationDuration = 2;
[imageAnimation2 startAnimating];
[self loadSoundEffectAudio:@"Monkey_10"];
[self performSelector:@selector(stopSoundEffectAudio) withObject:nil afterDelay:4];
break;
I have lot of such case statements which would fire various UIView animations. I would like to write a module and parametrize these so I don't have to repeat similar code over and over. What is the best way to pass (parametrized) values for animationRepeatCount & animationDuration?
case 10: //Animation Number 10
//.........
imageAnimation2.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"monkey_dancing_01.png"],
[UIImage imageNamed:@"monkey_dancing_02.png"],
[UIImage imageNamed:@"monkey_dancing_03.png"],
[UIImage imageNamed:@"monkey_dancing_04.png"],
nil];
imageAnimation2.animationRepeatCount = 4;
imageAnimation2.animationDuration = 2;
[imageAnimation2 startAnimating];
[self loadSoundEffectAudio:@"Monkey_10"];
[self performSelector:@selector(stopSoundEffectAudio) withObject:nil afterDelay:4];
break;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的资源和动画的规律性,您可以创建一些实用方法来处理其中的大部分内容。
就像这样说:
上面的代码将动画加载到一个具有非常规则的命名约定的数组中(XXXX.png)。它们也都基于相同的帧速率,因此我可以同时构建持续时间。
Depending on how regular your assets and animations are, you could make some utility methods to handle much of that.
Like say:
The above code loads up animations into an array with very regular naming conventions (XXXX.png). They are also all based on the same framerate so I can build the duration at the same time.