0

我正在 Xcode 4.3.2 中开发游戏

在游戏中我需要经常调用这个函数来在屏幕上添加两个带有动画的图像,第一个图像从左边进入,第二个从右边进入,2 秒后消失:

-(void) PandaAnimation2 {
[pandablock3 removeFromSuperview];
[awesomeview removeFromSuperview];

//pandablock3 is a UIImageView
//awesomeview is a UIImageView
pandablock3.frame = CGRectMake(400, 101, 111, 208);
awesomeview.frame = CGRectMake(-400, 9, 230, 68);

[self addSubview:pandablock3];
[self addSubview:awesomeview];


[UIImageView beginAnimations:@"movein" context:NULL];
[UIImageView setAnimationBeginsFromCurrentState:YES];
[UIImageView setAnimationDelegate:self];
[UIImageView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIImageView setAnimationDuration:2.0];

pandablock3.frame = CGRectMake(208, 101, 111, 208);
awesomeview.frame = CGRectMake(11, 9, 230, 68);

[UIImageView commitAnimations];

[UIImageView beginAnimations:@"moveout" context:NULL];
[UIImageView setAnimationDelay:2.0];
[UIImageView setAnimationBeginsFromCurrentState:YES];
[UIImageView setAnimationDelegate:self];
[UIImageView setAnimationDuration:1.0];
[UIImageView setAnimationCurve:UIViewAnimationCurveEaseOut];

pandablock3.frame = CGRectMake(400, 101, 111, 208);
awesomeview.frame = CGRectMake(-400, 9, 230, 68);
[UIImageView commitAnimations];

}

效果很好,但只有一次!为什么?

请帮忙!

4

1 回答 1

0

很难说不看是什么在调用您的代码,但我的猜测是在第一次调用后被释放pandablock3awesomeview因此nil在第二次调用中。

于 2012-06-05T20:11:05.387 回答