简体   繁体   English

播放声音完成后如何关闭视图

[英]how can i close view after completion of playing sound

hi i am new to iphone. 嗨,我是iPhone新手。 what i did is displaying a grid of images and by selecting the image from the grid selected image will be displayed on imageview along with sound i am using the fallowing code to play audio 我所做的是显示图像网格,通过从网格中选择图像,所选图像将与声音一起显示在imageview上,我正在使用休憩代码来播放音频

NSString *newAudioFile = [[NSBundle mainBundle] pathForResource:@”MusicFile”  ofType:@”mp3″];
AVAudioPlayer *audioPlayer =  [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:newAudioFile] error:NULL];

[audioPlayer play];

Now what i need is how can i get to view after completion of playing sound file post some code. 现在我需要的是在完成播放声音文件后发布一些代码后如何查看。 thank u. 感谢你。

You can use – audioPlayerDidFinishPlaying:successfully: method of you AVAudioPlayer delegate (probably your UIViewController) and inside of it you can dismiss the view releasing it and doing [myView removeFromSuperview] 您可以使用– audioPlayerDidFinishPlaying:successfully:您的AVAudioPlayer 委托方法(可能是您的UIViewController),在其中可以关闭释放它的视图并执行[myView removeFromSuperview]

Have a look at this answer 看看这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM