本文介绍了如何在仅限肖像的应用程序中使用MPMovieViewController播放风景视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用支持的界面方向是纵向和上下颠倒。但是,当播放视频时,我希望它能够播放全屏风景。目前使用此代码,它只播放肖像,即使设备被旋转:

My app's supported interface orientations are Portrait and Upside down. However, when a video is played, I want it to play full screen landscape. Currently with this code, it only plays portrait, even when the device is rotated:

[player.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
player.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self presentMoviePlayerViewControllerAnimated:player];

如何强制它进入横向模式?

How can I force it into landscape mode?

推荐答案

以下是我的工作方式:

在项目文件中,确保您支持横向方向


现在所有的ViewControllers仍然应该是Portrait Only,添加此代码

Here is how I do it:
In the project file, make sure you are supporting the Landscape Orientations
Now in all of your ViewControllers that should still be Portrait Only, add this code

//ios6
- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

//ios4 and ios5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

我已经同时进行了iOS5和iOS6调用,以便我的代码可以运行双方。

I have put in both the iOS5 and iOS6 calls so that my code will run on both.

当您的MPMoviePlayerController视图变为全屏时,它将是一个新的ViewController,它在其他所有内容之上。因此,将允许根据项目的支持的接口方向进行旋转。它不会看到你强迫其他ViewControllers进入Portrait的位置。

When your MPMoviePlayerController view becomes fullscreen, it will be a new ViewController layered on top of everything else. So, it will be allowed to rotate according to the Supported Interface Orientations of the Project. It will not see where you forced the other ViewControllers into Portrait.

这篇关于如何在仅限肖像的应用程序中使用MPMovieViewController播放风景视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 17:31