这里是编程新手。使用本指南设置我的页面:http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/
我用来播放音频的代码是:
NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"mp3"];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
我的目标是在按下按钮时播放不同的声音文件,每个声音对应于页码。该按钮在整个页面中都是不变的,只是试图更改将其连接到每个页面的新声音的代码。
最佳答案
您需要跟踪当前页面。委托(delegate)方法 pageViewController:didFinishAnimating:previousViewControllers:transitionCompleted:
将告诉您用户是否更改了页面,因此您可以更新当前页码变量。它看起来像某种东西,
-(void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
if(completed)
{
//update variable and play the audio file respectively
}
}
关于ios - 如何使用按钮根据页码播放不同的声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27812657/