如何旋转MPMoviePlayerController视频但不旋转其父视图

3
我的MPMoviePlayerController视图已添加为另一个视图控制器的子视图。当我在全屏播放视频并翻转模拟器时,视频不会翻转,父视图也不会翻转。然而,当我在旋转方法中添加return YES(检查下面的代码)时,视频在全屏播放时旋转,正如我想要的那样,但父视图也旋转了,这是我不想要的,因为我没有为父视图设计横向视图。当视频处于全屏状态时,如何只允许视频旋转而不是父视图??
以下是我使用的代码:
对于视频:
- (void)viewDidAppear:(BOOL)animated {

    NSBundle *bundle=[NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@"MainPageMovie" ofType:@"mp4"];
    NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    theMovie.view.frame = CGRectMake(115.0, 156.0, 200.0, 150.0);
    [self.view addSubview:theMovie.view];
    [theMovie play];

    [super viewDidLoad];
    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
}

对于旋转方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return YES;
}
1个回答

0

一个简单的方法是使用MPMoviePlayerViewController来显示电影。作为一个独立的视图控制器,这应该会为您处理旋转。

如果你真的想通过添加MPMoviePlayerController作为子视图来实现它,你面临着更困难的任务。基本上,你需要监听UIDeviceOrientationDidChangeNotification并根据设备的方向对电影播放器视图应用适当的transformboundscenter


所以基本上我要么为父视图设计一个横向视图,这会让我为整个应用程序设计横向视图,要么保持视频在纵向视图中播放,是吗?哈哈,无论如何还是谢谢:)我会尝试在单独的视图上添加视频。这应该可以解决我的问题:) - Marwan Al-Taher

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接