二次接触动画 [英] Second touch animation

查看:75
本文介绍了二次接触动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图掌握Xcode并在过去几周中似乎取得了一些进展。

Trying to get to grips with Xcode and seem to be making some progress over the last few weeks.

有人知道自定义按钮可以执行以下操作吗?

Does anyone know a way that a custom button can do a different set of animations on a second click.

所以可以说我有一个自定义按钮及其Mario,当我单击它时,他从屏幕中间运行,从屏幕的右侧移出,然后从屏幕的左侧回到中间,他也会发出声音。

So let say I have a custom button and its of Mario, when i click it he runs from the middle of the screen and out of the right hand side of the screen and then runs back in to the middle from the left of the screen, he also makes noise.

我已经用这个实现了代码:

I have achieved this using this code:

- (IBAction)marioRunning_clicked:(id)sender
{

    [UIView animateWithDuration:1.50 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        marioRunning.center = CGPointMake(350.5, 456.0);
    } completion:^(BOOL finished) {
        if (finished) {
            [UIView animateWithDuration:0.00 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
                marioRunning.center = CGPointMake(-30.5, 456.0);
            } completion:^(BOOL finished) {
                if (finished) {
                    [UIView animateWithDuration:1.50 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
                        marioRunning.center = CGPointMake(160.0, 456.0);
                    } completion:^(BOOL finished) {
                        if(finished)  // NSLog ( @"Finished !!!!!" );
                        marioRunning.center = CGPointMake(160.0, 456.0);
                    }];
                }
            }];
        }
    }];

    marioRunning.imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"mario-running2"],[UIImage imageNamed:@"mario-running3"],nil];

    marioRunning.imageView.animationDuration = 0.15;
    marioRunning.imageView.animationRepeatCount = 19;

    [marioRunning.imageView startAnimating];
}

我如何让他在下次点击时制作第二组动画?例如,如果我第二次点击他,而不是从左到右奔跑,他将上下跳跃吗?

How could I make him do a second set of animations on the next click? For example instead of running from left to right, if i tap him the second time he will Jump up and down?

推荐答案

使用按钮的选定状态决定要制作的动画

Use the selected state of the button to decide which animation to do

-(void)buttonClicked:(UIButton*)button
{
     if(button.selected)
     {
          [self doAnimation1];
     }
     else
     {
          [self doAnimation2];
     }

     button.selected = !button.selected;
}

这篇关于二次接触动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆