Iphone 如何在播放完整的soundloop时避免用户输入

Iphone 如何在播放完整的soundloop时避免用户输入,iphone,xcode,audio,nsarray,Iphone,Xcode,Audio,Nsarray,我有一些UIImageView(动物),通过触摸它们,一个特定的声音循环开始播放。 但是,如果用户在同一视图上触摸两次或两次以上,则适当的声音循环会以重叠的方式反复启动。我想让触摸的声音播放一次,直到它结束,然后用户可以开始下一次。声音循环的持续时间约为3秒。我尝试了“睡眠(3)”功能,但它会在声音播放前停止程序 但是如果用户触摸另一个视图,两种不同的声音可能会重叠 #pragma mark - -(void)touchesBegan:(NSSet*)touches withEvent:(UI

我有一些UIImageView(动物),通过触摸它们,一个特定的声音循环开始播放。 但是,如果用户在同一视图上触摸两次或两次以上,则适当的声音循环会以重叠的方式反复启动。我想让触摸的声音播放一次,直到它结束,然后用户可以开始下一次。声音循环的持续时间约为3秒。我尝试了“睡眠(3)”功能,但它会在声音播放前停止程序

但是如果用户触摸另一个视图,两种不同的声音可能会重叠

#pragma mark -

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
//Soundfile names in array arrAnimalde
arrAnimalde = [NSArray arrayWithObjects:@"Hund" ,@"Schwein" ,@"Ferkel", nil];

// here are some Views and their triggers
if([touch view] == img_hund){
    trigAnimal = 0;
    }

if([touch view] == img_schwein){
    trigAnimal = 1;
    }

if([touch view] == img_ferkel){
    trigAnimal = 2;
      }

    AudioServicesCreateSystemSoundID ((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource: [arrAnimalde objectAtIndex: trigAnimal]
 ofType: @"wav"]], &soundFileObject);
    AudioServicesPlaySystemSound (self.soundFileObject);

//if the trigger is the same as before play the sound only once and completely
      }
}
也请写下替代方案——也许可以在每个if语句中开始并保持声音


Thanxx

在调用
AudioServicesPlaySystemSound
之前,您可以调用
[[UIApplication sharedApplication]beginIgnoringInteractionEvents]
。声音播放完毕后,您可以调用
[[UIApplication sharedApplication]endIgnoringInteractionEvents]这个代码将阻止你的应用程序中的所有东西的交互,这意味着只要你的声音播放,你的用户就不能做任何事情。只考虑阻止你的代码> -(空)触摸开始:(NSSET*)触摸下面的内容:(uivith*)事件
消息。只需检查一个布尔值即可实现 如果您的声音仍在播放。要了解声音何时结束,请使用此函数注册适当的回调:

OSStatus AudioServicesAddSystemSoundCompletion (
   SystemSoundID                           inSystemSoundID,
   CFRunLoopRef                            inRunLoop,
   CFStringRef                             inRunLoopMode,
   AudioServicesSystemSoundCompletionProc  inCompletionRoutine,
   void                                    *inClientData
);

谢谢你,这是有史以来最快的答案!这就是我想要的,希望我能实现它。Thanx to Gouloises:我用这个解决方案编码它:…[self-performSelector:@selector(enable)with Object:yourImageView afterDelay:1.0];…-(void)enable{yourImageView.userInteractionEnabled=YES}