2

我有一个完全处于纵向模式的应用程序。(iOS 5 及更高版本)我有一个使用 MPMoviePlayerController 播放的视频,现在在这个视频中,我希望当用户旋转 iPhone 时,视频应该进入横向模式(全屏)。当视频结束时,视频应该再次进入纵向模式。代码:

    -(void)PlayVideo:(NSURL*)videoUrl
{


    moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
    [moviePlayerController.view setFrame:CGRectMake(6, 69, 309, 196)];
    [self.view addSubview:moviePlayerController.view];
    //    moviePlayerController.fullscreen = YES;


    moviePlayerController.controlStyle = MPMovieControlStyleNone;
    [self.view bringSubviewToFront:self.shareView];
    [self.view bringSubviewToFront:self.qualityView];

    [moviePlayerController play];

    // Register to receive a notification when the movie has finished playing.
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:moviePlayerController];

}

应用程序的其余部分,我只想要纵向。我如何实现这一目标?

4

2 回答 2

4

首先,您需要将支持界面方向设置为纵向横向

如此处所示

现在在每个 UIViewController 你需要重写这些方法 -

对于iOS 5 -

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (BOOL)shouldAutorotate
{
    return NO;
}

适用于iOS 6

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

在要添加 MPMoviePlayerController 覆盖的 UIViewController 中 -

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
于 2013-07-31T08:50:47.433 回答
0

我用视频播放器的示例创建了 Xcode 项目。它可以在横向模式下全屏显示视频。你可以下载它。我希望它对你有帮助。

第二。代替

[self.view bringSubviewToFront:self.shareView];
[self.view bringSubviewToFront:self.qualityView];

你应该这样写:

    [moviePlayerController.view insertSubview: self.shareView
                                      atIndex: 2];

    [moviePlayerController.view insertSubview: self.qualityView
                                      atIndex: 2];

然后 shareView 和 qualityView 出现在电影播放器​​的顶部。

于 2013-08-01T06:17:01.293 回答