触摸音频已结束

发布于 2024-12-08 19:07:01 字数 910 浏览 0 评论 0原文

在 TouchesEnded 上我想做两件事: 1)将视图返回到其原始位置 - 这很好用。 2)如果触摸在“是”视图上结束,我想播放音频声音,而在“否”视图上则播放不同的声音。

我该怎么做?

此时,每次触摸结束时,我都会播放“否”的声音 - 这不好。

我对此很陌生,所以请解释一下基础知识:)下面是我当前的代码。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{

    yesletter1.frame = keepYesLetter1Place;
    yesletter2.frame = keepYesLetter2Place;
    yesletter3.frame = keepYesLetter3Place;
    yesletter4.frame = keepYesLetter4Place;
    notletter1.frame = keepNoLetter1Place; 
    notletter2.frame = keepNoLetter2Place;
    notletter3.frame = keepNoLetter3Place;
    notletter4.frame = keepNoLetter4Place;   

    NSString *path = [[NSBundle mainBundle]
                      pathForResource:@"no"ofType:@"wav"];
    AVAudioPlayer* theAudio = [[AVAudioPlayer alloc]
                               initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

    [theAudio play];
}

On TouchesEnded I want to do two things:
1) return the view to its original position - this works fine.
2) I want to play an audio sound if the touch ended on the YES vies and a different sound for the NO views.

How can I do this?

At this moment my sound for NO will play for every touch ended - and this is not good.

I am new to this so please explain the basics :) my current code below.

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{

    yesletter1.frame = keepYesLetter1Place;
    yesletter2.frame = keepYesLetter2Place;
    yesletter3.frame = keepYesLetter3Place;
    yesletter4.frame = keepYesLetter4Place;
    notletter1.frame = keepNoLetter1Place; 
    notletter2.frame = keepNoLetter2Place;
    notletter3.frame = keepNoLetter3Place;
    notletter4.frame = keepNoLetter4Place;   

    NSString *path = [[NSBundle mainBundle]
                      pathForResource:@"no"ofType:@"wav"];
    AVAudioPlayer* theAudio = [[AVAudioPlayer alloc]
                               initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];

    [theAudio play];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

罗罗贝儿 2024-12-15 19:07:01

解决这个问题的方式不是我想要的,但现在可以了。
对于某些物体,我有两种不同的声音,一种声音,另一种声音。
我所做的是为每个对象添加一个标志,并执行 if(flag1 == 0 || flag2 == 0 等...) 播放声音 1,否则播放声音 2。
在另一种方法中,我用标志做了其他事情。

我确信对此有更好的解决方案:)但现在一切正常了。

Solved this issue not the way i wanted but thing work now.
I have 2 different sounds for some objects one sound and the other another sound.
What i did is added a flag for each object and did if(flag1 == 0 || flag2 == 0 ect...) play sound 1 else play sound 2.
in another method which does something else i played with the flags.

I am sure there is a better solution for this :) but things work now.

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