我有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