UIImage View动画有效一次......为什么?

时间:2012-06-05 20:07:01

标签: xcode animation uiimageview uiimage

我正在开发Xcode 4.3.2中的游戏

Ingame我需要经常调用这个函数在屏幕上添加两个带动画的图像,第一个图像从左边输入,第二个从右边输入,在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];

}

它运作良好,但只有一次! 为什么呢?

请帮忙!

1 个答案:

答案 0 :(得分:0)

很难说没有查看调用代码的内容,但我的猜测是pandablock3并且awesomeview在第一次调用后被释放,因此在第二次调用中是nil