下面是我正在使用的一些代碼。核心動畫+核心音頻+睡眠不會發生在預期的順序
我想/什麼期待:
- 圖片淡入;聲音播放;延遲;圖像淡出。
發生
- 延遲,聲音播放什麼,圖像淡入然後
任何幫助非常讚賞後淡出。
ViewController.m
[self fadein];
NSString *tempFN;
SystemSoundID soundID;
tempFN = [[NSString alloc] initWithFormat:@"%@.caf",
[myGlobals.gTitleArray objectAtIndex:myGlobals.gQuoteCountForLoop]];
NSString *soundFilePath = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], tempFN];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof (sessionCategory),
&sessionCategory);
AudioServicesCreateSystemSoundID((__bridge CFURLRef)soundFileURL, &soundID);
AudioServicesPlaySystemSound(soundID);
// Now fade-out the image after a few seconds delay
sleep(3);
[self fadeout];
-(IBAction)fadein
{
[UIImageView beginAnimations:NULL context:nil];
[UIImageView setAnimationDuration:2];
[faceImage setAlpha:0.3];
[UIImageView commitAnimations];
}
-(IBAction)fadeout
{
[UIImageView beginAnimations:NULL context:nil];
[UIImageView setAnimationDuration:1];
[faceImage setAlpha:0];
[UIImageView commitAnimations];
}