2013-01-21 80 views
1

我有以下代碼:異步聽起來

SystemSoundID soundID; 
NSString *soundFile = [[NSBundle mainBundle] pathForResource: _sound ofType:@ "wav"]; 
AudioServicesCreateSystemSoundID((__bridge CFURLRef) [NSURL fileURLWithPath:soundFile], &soundID); 
AudioServicesPlaySystemSound(soundID); 


    [UIView animateWithDuration: 0.6f 
          delay: 0.1f 
         options: UIViewAnimationTransitionCurlUp 
        animations:^{ 
         [appDelegate.presstobook setFrame: CGRectMake(136, appDelegate.window.frame.size.height - 50, 47, 47)]; 
        } 
        completion:^(BOOL finished){ 

         presstobook = NO; 
        } 
    ]; 

我怎樣才能做到這一點使聲音播放,而不影響其他代碼?我不想播放聲音來暫停代碼?如何更改代碼,以便在不影響其餘代碼的情況下異步播放聲音?謝謝!

回答

2

是什麼讓你覺得這會暫停代碼?該文檔說:

因爲聲音可能會播放幾秒鐘,所以此函數是異步執行的。

如果在這裏有東西阻止,我想這是AudioServicesCreateSystemSoundID()。但即使這不會阻止,每次想要播放聲音時創建其中之一可能不是一個好主意,尤其是如果您永遠不處理它們的話。您應該在某種設置中創建一次,然後隨時用AudioServicesPlaySystemSound()播放。