我在这里有一个滚动打开的小动画,然后我只是将其反转以再次关闭滚动。我有两个问题。
- 我只想在动画运行时播放声音文件。除了对动画的开始和停止时间进行计时,我该怎么做?有没有办法将它与动画执行联系起来?
- 有没有办法反向运行相同的数组,而不是在拥有两个单独的数组时浪费内存?
** 示例代码
- (void)loadAnimationArray;
{
// scroll close frame order
animationclose=[[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"frame1.png"],
[UIImage imageNamed:@"frame2.png"],
[UIImage imageNamed:@"frame3.png"],
...
[UIImage imageNamed:@"frame25.png"],
[UIImage imageNamed:@"frame26.png"],nil];
// scroll open order
animationopen=[[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"frame26.png"],
[UIImage imageNamed:@"frame25.png"],
[UIImage imageNamed:@"frame24.png"],
...
[UIImage imageNamed:@"frame3.png"],
[UIImage imageNamed:@"frame2.png"],
[UIImage imageNamed:@"frame1.png"],nil];
}
- (IBAction)buttonOpen:(id)sender
{
// default image post animation
_imageScrollAnimation.image = [UIImage imageNamed:@"frame1.png"];
// setting animation parameters
self.imageScrollAnimation.animationDuration=3;
self.imageScrollAnimation.animationRepeatCount=1;
self.imageScrollAnimation.animationImages=animationopen;
[self.imageScrollAnimation startAnimating];
}
- (IBAction)buttonClose:(id)sender
{
// default image post animation
_imageScrollAnimation.image = [UIImage imageNamed:@"frame26.png"];
// setting animation parameters
self.imageScrollAnimation.animationDuration=3;
self.imageScrollAnimation.animationRepeatCount=1;
self.imageScrollAnimation.animationImages=animationclose;
[self.imageScrollAnimation startAnimating];
}