iOS7 viewController和MPMoviePlayerViewController旋转

时间:2014-02-19 11:35:42

标签: ios objective-c uiviewcontroller rotation mpmoviewcontroller

我尝试了很多东西,但我仍然无法在我的所有应用中只旋转1个viewControllor。 我希望显示(或旋转)仅在景观中使用MPMoviePlayerViewController

Facebook 应用中的视频一样。该应用仅限于纵向,但视频可以旋转。 播放视频后,应用程序以纵向模式返回。 我能够进行评估但是在“完成”后,videoplayer按钮点击了横向模式下的视图返回。

我该如何解决这个问题?

非常感谢。

2 个答案:

答案 0 :(得分:5)

  1. 为播放视频创建新的视图控制器

  2. 单击Project,然后单击Target。在“部署信息”下的“常规”类别中,启用“所有轮换”

  3. 现在打开您的根视图控制器并放置以下行。您应用的方向

  4. 代码:

    -(BOOL)shouldAutorotate
    {
        return TRUE;
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
        {
            return UIInterfaceOrientationMaskPortrait;
        }
        else
        {
            return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
        }
    }
    

    4.现在,如果您使用addsubview方法来表示其他ViewController的视图,则无需将orintation方法应用于其他控制器。但是如果您使用了PresentController方法的任何vc,则将方向方法添加到该控制器

答案 1 :(得分:2)

创建一个新的UIViewController,用于展示视频。

创建MPMoviePlayerController属性

@property (nonatomic, strong) MPMoviePlayerController* moviePlayerController;

然后在viewDidLoad中,试试这个:

 - (void)viewDidLoad
    {
        [super viewDidLoad];

        _moviePlayerController = [[MPMoviePlayerController alloc] init];
        _moviePlayerController.controlStyle = MPMovieControlStyleFullscreen;

        _moviePlayerController.contentURL = [NSURL URLWithString:@"example.com"];

        // Rotating the player to landscape position
        _moviePlayerController.view.frame = CGRectMake(0.0f,
                                            0.0f,
                                            [UIScreen mainScreen].bounds.size.height,
                                            [UIScreen mainScreen].bounds.size.width);

        _moviePlayerController.view.transform = CGAffineTransformMakeRotation(M_PI_2);
        _moviePlayerController.view.center = self.view.center;

        UIView *playerView = _moviePlayerController.view;


        [self.view insertSubview:playerView atIndex:0];
        [_moviePlayerController prepareToPlay];
    }

希望它有所帮助。