2011-07-15 15 views
0

私は頭を下げている問題があり、解決するのが簡単なはずです。ここに私のコードは次のとおりです。ビデオの再生後にiPhoneが方向を強制する

-(IBAction)playMovie:(id)sender{ 

    NSString *filepath = [[NSBundle mainBundle] pathForResource:@"myMovie" ofType:@"MOV"]; 
    NSURL *fileURL = [NSURL fileURLWithPath:filepath]; 
    moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL]; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlaybackComplete:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:moviePlayerController]; 

    [self.view addSubview:moviePlayerController.view]; 
    //[moviePlayerController setOrientation:UIInterfaceOrientationLandscapeLeft]; 
    moviePlayerController.fullscreen = YES; 
    moviePlayerController.scalingMode = MPMovieScalingModeFill;  

    [moviePlayerController play]; 

} 

- (void)moviePlaybackComplete:(NSNotification *)notification 
{ 

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; 

    moviePlayerController = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:MPMoviePlayerPlaybackDidFinishNotification 
                object:moviePlayerController]; 

    [moviePlayerController.view removeFromSuperview]; 
    [moviePlayerController release]; 
} 

と方向:最初に、必要に応じて

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
    if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { 
     return(YES); 
    } 

    if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { 
     return([moviePlayerController isFullscreen]); 
    } 




    return(NO); 

} 

これは動作します。オリエンテーションは最初に肖像画に強制され、ムービーが再生され、ランドスケープではムービーが回転し、ランドスケープで表示されます。その後、doneをクリックすると、ムービーは終了し、インターフェースはランドスケープのままになります。私は今理想的には、すぐに映画が終わった方法は、それを起動IOS 4.0

で廃止されているようだ

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait]; 

のようなソリューションを見てきました...それはバックポートレートモードに強制する必要があります自動的にポートレートに回転する必要があります!

どのようなソリューションですか?

答えて

1

これを試してみてください:

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(moviePlaybackComplete:) 
             name:MPMoviePlayerWillExitFullscreenNotification 
             object:moviePlayerController]; 
関連する問題