我的 MPMoviePlayerController View 作为 subview 添加到另一个 View Controller 的 View 中。当我全屏播放视频并翻转模拟器时,视频不会翻转,父 View 也不会翻转。但是,当我将 return YES
添加到旋转方法(检查下面的代码)时,视频在全屏时按照我想要的方式旋转,但父 View 也会旋转,这是我不想要的,因为我没有为父 View 设计横向 View 。如何在全屏而不是父 View 下仅允许视频旋转?
这是我使用的代码:
对于视频:
- (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;
}
最佳答案
一个简单的方法是使用 MPMoviePlayerViewController 来显示电影。作为一个单独的 View Controller ,这应该为您处理旋转。
如果您确实想通过添加 MPMoviePlayerController 作为 subview 来完成此操作,那么您面临着更困难的任务。基本上,您必须监听 UIDeviceOrientationDidChangeNotification 并根据设备的方向将适当的 transform
、bounds
和 center
应用于电影播放器 View .
关于iphone - 如何旋转 MPMoviePlayerController 视频但不旋转其 super View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5609176/