MPMoviePlayerViewController旋转问题

时间:2013-02-10 14:11:05

标签: iphone objective-c video

我有一个" VideoLecturesDetails"在tabbarcontroller中,这个类有这个方法

-(IBAction) playVideo{
    NSString *fileURL = [NSString stringWithFormat:@"%@" ,FileName];

    NSURL* videoURL = [NSURL URLWithString:fileURL];                
    MPMoviePlayerViewController* theMoviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
    [theMoviePlayer shouldAutorotate];
    [self presentMoviePlayerViewControllerAnimated:theMoviePlayer];
}

-(BOOL)automaticallyForwardAppearanceAndRotationMethodsToChildViewControllers {
    return NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return YES;//This allows all orientations, set it to whatever you want
}

因此,在播放视频时,自动旋转不起作用,如何使用此方法启用自动旋转。

1 个答案:

答案 0 :(得分:1)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;//This allows all orientations, set it to whatever you want

}

以上代码在IOS 6中不再可用!对于使用IOS 5或更低版本的应用程序的用户,您应该保留它。

在IOS 6中,你应该按如下方式实现轮换:

在appDelegate中: 使用:

window.rootViewController = viewController

而不是:

[window addSubview:viewController.view];

并添加:

- (NSUInteger) application:(UIApplication *)application 

supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return  UIInterfaceOrientationMaskAll;
}

每次旋转都会发生这种情况。

并在视图控制器中添加以下内容:

-(BOOL)shouldAutorotate {

    return YES;
}
-(NSUInteger)supportedInterfaceOrientations {

        return UIInterfaceOrientationMaskAllButUpsideDown;
}