如何将一个void(摇晃手势)一个IBAction为(按钮)里面呢? [英] How do i put a void(shake gesture) inside a IBAction(button)?

查看:124
本文介绍了如何将一个void(摇晃手势)一个IBAction为(按钮)里面呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个应用程序,我已经碰到了一个问题。
我的应用程序有一个播放按钮,一旦用户presses它的动画剧本和完成。
我已经创建了code以上,我将在下面显示的,但我需要一些帮助。
当玩家preSS的发挥,它应该显示标签上说摇启动,当用户晃动的iPhone上的标签将消失,动画将开始。我不能够把动画code中的IBAction为code内。请帮助:)

I am creating an app and I have bumped into a problem. My app has a play button, once the user presses it a animation plays and finishes. I have created the above in code which I will display below, but I need some help. When the player press's play, it should display a label saying shake to start, and when the user shake's the iPhone the label will disappear and the animation will start. I am not able to put the animation code inside the IBAction code. Please help :)

-(IBAction)startanimation { 



animation.animationImages= [NSArray arrayWithObjects:
                                [UIImage imageNamed:@"Frame0.png"],
                                [UIImage imageNamed:@"Frame1.png"],
                                [UIImage imageNamed:@"Frame2.png"],
                                [UIImage imageNamed:@"Frame3.png"],
                                [UIImage imageNamed:@"Frame4.png"],
                                [UIImage imageNamed:@"Frame5.png"],
                                [UIImage imageNamed:@"Frame6.png"],
                                [UIImage imageNamed:@"Frame7.png"],
                                [UIImage imageNamed:@"Frame8.png"],
                                [UIImage imageNamed:@"Frame9.png"],
                                [UIImage imageNamed:@"Frame10.png"],
                                [UIImage imageNamed:@"Frame11.png"],
                                [UIImage imageNamed:@"Frame12.png"],
                                [UIImage imageNamed:@"Frame13.png"],
                                [UIImage imageNamed:@"Frame14.png"], 
                                nil];

    [animation setAnimationRepeatCount:1];
    animation.animationDuration = 1;
    [animation startAnimating];


    button.hidden = 1;
    animation.hidden = 0;
    Menu.hidden = 0;
    replay.hidden = 0;



}

我在这样的编码是一个初学者,请解释任何答案:)

I am a beginner at coding so please explain any answers :)

感谢

推荐答案

在您的IBAction为设置一个名为BOOL类似readyToShake为TRUE。然后在你摇监听器检查,如果readyToShake是真,如果是,启动动画。如果是假的,忽略摇晃手势。

In your IBAction set a BOOL named something like "readyToShake" to TRUE. Then in your Shake listener check for if "readyToShake" is TRUE, if it is, start the animation. If it is FALSE, ignore the shake gesture.

这篇关于如何将一个void(摇晃手势)一个IBAction为(按钮)里面呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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