xcode - 触摸音频结束

标签 xcode cocoa-touch audio playsound

在TouchesEnded上,我想做两件事:
1)将 View 返回其原始位置-可以正常工作。
2)如果触摸"is"结束而我想播放音频声音,而“否” View 出现其他声音。

我怎样才能做到这一点?

此时,我的NO声音会在每次触摸结束时播放-不好。

我对此并不陌生,所以请在下面说明基本知识:)我当前的代码。

- (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];
}

最佳答案

解决了这个问题,不是我想要的,而是现在可以正常工作。
对于某些物体,我有2种不同的声音,一种声音,另一种声音。
我所做的是为每个对象添加了一个标志,并且if(flag1 == 0 || flag2 == 0 ect ...)播放声音1否则播放声音2。
在另一种方法中,我做了一些标志。

我敢肯定有一个更好的解决方案:)但现在一切正常。

关于xcode - 触摸音频结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7695683/

相关文章:

iphone - iPhone 上的视频卡拉 OK 开发

c - 如何在命令行应用程序中使用 Instruments 和显示控制台

ios - 跨 ViewController 保存信息

ios - PayU支付网关支付成功后如何得到响应?

c# - 如何在C#中比较两个波形的相似性?

ios - 访问 AVAudioSession 的音频缓冲区

ios - Swift 4 UIButton 附加在 View 上

ios - iPhone 不支持任何架构。 (不支持的架构)

iphone - 字符串 2012-11-09T00 :00:00 to short Form of date in iphone

iphone - 无法将对象添加到 NSMutableArray