我有2个视图控制器,我用AVAudioPlayer在第一个视图控制器中播放音乐。 我去第二视图控制器和停止音乐:如何让audioplayer再次玩?
[audioPlayer stop];
[UIView beginAnimations:@"Curl View" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[self.view addSubview:secondController.view];
[UIView commitAnimations];
当我再回到第一个视图控制器再次,我想再次播放我的音乐,但代码不会再碰viewDidLoad中。 这里是我的代码回去:
[UIView beginAnimations:@"Flipping View" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view.superview cache:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];
请分享我的一些解决方案还是什么that..Thanks后的代码执行预先
我加void void viewWillAppear,当我从secondController返回时,编译器不执行viewWillAppear。我从控制台看它也没有被编译器触及。你能稍微详细一点吗? – 2012-03-01 08:54:56
你能否显示你的viewDidAppear方法定义。 – 2012-03-01 09:22:28
NSLog(@“View Did Appear”);您可以使用NSURL * url = [NSURL fileURLWithPath:[NSString stringWithFormat:@“%@/BGMCover2.mp3”,[[NSBundle mainBundle] resourcePath]]]; \t NSError * error; \t audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; \t audioPlayer.numberOfLoops = -1; \t [audioPlayer play]; – 2012-03-01 09:30:33