UIImageView 的动画仅运行一次
我正在写一个游戏。攻击者杀死一名士兵后,会显示一个掉落的 UIImageView,上面写着 experience+1。
现在,当我杀死第一个士兵时,动画可以正确显示,但当杀死第二个士兵及以后时不显示。
动画代码,方法名称为showGainXPAnimationAfterKillSoldier。
imgGainXPAfterKillSoldier.hidden = FALSE;
[imgGainXPAfterKillSoldier.layer removeAllAnimations];
imgGainXPAfterKillSoldier.frame = CGRectMake(140, 220, 53, 19);
// a loop to show animation.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:1.5];
//imgGainXPAfterKillSoldier.frame = CGRectMake(100, 200, 53, 19);
CGAffineTransform transform = CGAffineTransformMakeTranslation(-112, 215);
imgGainXPAfterKillSoldier.transform = transform;
//imgGainXPAfterKillSoldier.alpha = 0.0f;
[UIView commitAnimations];
调用动画代码,
if (killedSoldierCount>0) {
// add imgview to show gained XP.
if (imgGainXPAfterKillSoldier) {
MWLog(@"remove it!");
[imgGainXPAfterKillSoldier.layer removeAllAnimations];
[imgGainXPAfterKillSoldier removeFromSuperview];
}
imgGainXPAfterKillSoldier.frame = CGRectMake(140, 220, 53, 19);
imgGainXPAfterKillSoldier.hidden = TRUE;
//imgGainXPAfterKillSoldier.alpha = 1.0f;
[self.view addSubview:imgGainXPAfterKillSoldier];
switch (killedSoldierCount) {
case 1:
// show add experience animation after kill soldier.
MWLog(@"kill a soldier, show XP+1 animation.");
[self showGainXPAnimationAfterKillSoldier:1];
break;
有什么问题吗?提前致谢!
I am writing a game. After attacker kills a soldier, a dropping UIImageView saying experience+1 will show.
Now, the animation shows correctly when I kills 1st soldier, but not show when killing 2nd soldier and later.
animation codes, method name is showGainXPAnimationAfterKillSoldier.
imgGainXPAfterKillSoldier.hidden = FALSE;
[imgGainXPAfterKillSoldier.layer removeAllAnimations];
imgGainXPAfterKillSoldier.frame = CGRectMake(140, 220, 53, 19);
// a loop to show animation.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:1.5];
//imgGainXPAfterKillSoldier.frame = CGRectMake(100, 200, 53, 19);
CGAffineTransform transform = CGAffineTransformMakeTranslation(-112, 215);
imgGainXPAfterKillSoldier.transform = transform;
//imgGainXPAfterKillSoldier.alpha = 0.0f;
[UIView commitAnimations];
call animation codes,
if (killedSoldierCount>0) {
// add imgview to show gained XP.
if (imgGainXPAfterKillSoldier) {
MWLog(@"remove it!");
[imgGainXPAfterKillSoldier.layer removeAllAnimations];
[imgGainXPAfterKillSoldier removeFromSuperview];
}
imgGainXPAfterKillSoldier.frame = CGRectMake(140, 220, 53, 19);
imgGainXPAfterKillSoldier.hidden = TRUE;
//imgGainXPAfterKillSoldier.alpha = 1.0f;
[self.view addSubview:imgGainXPAfterKillSoldier];
switch (killedSoldierCount) {
case 1:
// show add experience animation after kill soldier.
MWLog(@"kill a soldier, show XP+1 animation.");
[self showGainXPAnimationAfterKillSoldier:1];
break;
what is the problem? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在问题已经解决了。每次我想要制作动画时,我都会创建一个新的 UIImageView 来执行此操作。无需重复使用xib文件中定义的UIImageView。
now the problem is fixed. every time I want to animate, I create a new UIImageView to do that. without using the UIImageView defined in xib file repeatly.