如何防止iOS 6中的全屏视频旋转

时间:2013-03-20 13:23:29

标签: ios ios6

我有一个动态定义旋转配置的应用程序,因此我无法在项目文件中设置支持的旋转。

因此我必须处理新的shouldRotate方法(感谢Apple !!)

但是尽管已经覆盖了这些并且阻止了完整的UI显示除了肖像之外的任何东西。全屏显示视频视图并旋转时。视频将旋转至风景图。

是否还有另一种方法可以专门从旋转中预览视频?

1 个答案:

答案 0 :(得分:0)

这是一个使用MPMoviePlayerViewController子类的实现,支持纵向和纵向颠倒(但您可以轻松更改掩码)。 这可以在你建议的iOS 6中使用,以前的版本有不同的旋转选择器。

用法:

NSURL* url = [NSURL URLWithString:@"your_movie"];
MovieViewController* mvc = [[MovieViewController alloc] initWithContentURL:url];

// I did this from the app delegate. 
// You could push this view controller, present it modally, etc.

[self.window setRootViewController:mvc];

MovieViewController.h

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface MovieViewController : MPMoviePlayerViewController

- (id)initWithContentURL: (NSURL*) url;

@end

MovieViewController.m

#import "MovieViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@interface MovieViewController ()

@end

@implementation MovieViewController

- (id)initWithContentURL: (NSURL*) url
{
    self = [super initWithContentURL: url];
    if (self) {
        // Custom initialization


    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
    ROTATION CODE
 */
- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}


@end

结果(注意项目的旋转已在所有旋转中启用..):

enter image description here