如何防止iOS 6中的全屏视频旋转 [英] How do you prevent fullscreen video rotation in iOS 6

查看:213
本文介绍了如何防止iOS 6中的全屏视频旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an app whose rotation configuration is defined dynamically, therefore I cannot set the supported rotations in the project file.

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

Therefore I have to handle the new shouldRotate methods (thanks Apple!!)

但是尽管已经覆盖了这些并阻止完整的UI显示在除肖像之外的任何内容中。全屏显示视频视图并旋转时。视频将旋转为横向静止。

But despite having overriden these and prevented the full UI from displaying in anything but portrait. When a video view is displayed fullscreen and rotated. The video will rotate to landscape still.

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

Is there another way to preview the video specifically from rotating at all?

推荐答案

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

Here's an implementation using a MPMoviePlayerViewController subclass supporting portrait and portrait upside down (but you can easily change the mask). This works in iOS 6 as you suggested, prior versions have different rotation selectors.

用法:

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

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

Result (note rotation is enabled on the project for all rotations..):

这篇关于如何防止iOS 6中的全屏视频旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆