我有一些UIImageViews(動物),並通過觸摸他們一個特定的soundloop開始播放。 但是,如果用戶在同一個視圖上觸摸兩次或更多次,則合適的聲音循環將重複地重複開始。我想讓觸摸的聲音播放一次直到它結束,並且用戶可以下次開始播放。 soundloop的持續時間約爲。 3 sec.I試圖與「睡眠(3)的東西,但它的聲音響起之前停止PROG ..如何避免userinput播放soundloop完成
但是,如果用戶觸摸另一種觀點,兩種不同的聲音可以重疊
#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
謝謝你,有史以來最快的答案!這就是我正在尋找的東西,希望我能夠實現它。 – FredIce 2010-08-09 14:24:33
Thanou太Gouloises:我使用此解決方案編碼: ... [self performSelector:@selector(enable)withObject:yourImageView afterDelay:1.0]; ... - (void)enable { yourImageView.userInteractionEnabled = YES } – FredIce 2010-08-09 18:13:18