UIImageView 的动画仅运行一次

发布于 2024-10-30 22:33:10 字数 1632 浏览 3 评论 0原文

我正在写一个游戏。攻击者杀死一名士兵后,会显示一个掉落的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情丝乱 2024-11-06 22:33:10

现在问题已经解决了。每次我想要制作动画时,我都会创建一个新的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文