iphone - 如何旋转 MPMoviePlayerController 视频但不旋转其 super View

标签 iphone xcode ios4 video

我的 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 并根据设备的方向将适当的 transformboundscenter 应用于电影播放器​​ View .

关于iphone - 如何旋转 MPMoviePlayerController 视频但不旋转其 super View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5609176/

相关文章:

iphone - NSHTTPCookieStorage 的共享实例不会保留 cookie

ios - 如何在 Swift 中将绘图保存到 tableview 中?

iphone - 是否有在 iPhone 和 iPad 应用程序之间共享开发代码的最佳实践

ios - 使用 'Time Profiler' 时的空白仪器屏幕。最新版本的 Xcode 6

iphone - 困惑 : SKSpriteNode & SKTexture difference.

xcode - 在 Xcode 4.5 中,为什么我不能从 AssistantEditor 的 'Manual' 的右侧 Pane 中选择任何文件?

ios - main.jsbundle 不存在。升级到 react-native 0.63 后,这一定是一个错误。 main.jsbundle 问题

android - iOS 4 上的共享首选项

iphone - 删除应用程序时的委托(delegate)方法

iphone - 方法的条件实现