我如何在 IBAction(按钮)中放置一个 void(摇动手势)? [英] How do i put a void(shake gesture) inside a IBAction(button)?

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

问题描述

我正在创建一个应用程序,但遇到了一个问题.我的应用程序有一个播放按钮,一旦用户按下它,动画就会播放并完成.我已经在下面显示的代码中创建了上面的内容,但我需要一些帮助.当播放器按下播放时,它应该显示一个标签,说摇动开始,当用户摇动 iPhone 时,标签将消失,动画将开始.我无法将动画代码放入 IBAction 代码中.请帮忙:)

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 中,将名为readyToShake"之类的 BOOL 设置为 TRUE.然后在您的 Shake 侦听器中检查readyToShake"是否为 TRUE,如果是,则启动动画.如果为 FALSE,则忽略摇动手势.

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.

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

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