视频播放后iPhone强制定位

时间:2011-07-15 14:36:38

标签: iphone objective-c ios cocoa-touch ios4

我有一个问题,我正在努力解决这个问题。这是我的代码:

-(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);

}

这首先是按照需要工作的。最初将方向强制为纵向,然后电影播放和横向允许电影旋转并以横向方式查看。然后点击完成后电影结束,界面保持横向。我需要它被强制回到肖像模式...我已经看到像

这样的解决方案
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];

现在似乎已从ios 4.0中弃用

理想情况下,一旦电影结束方法触发,它应自动旋转为肖像!

任何解决方案?

1 个答案:

答案 0 :(得分:1)

试试这个:

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