2

我尝试了很多东西,但我仍然无法在我的所有应用程序中只旋转 1 个 viewControllor。我想在横向中仅显示(或旋转)带有MPMoviePlayerViewController.

喜欢Facebook应用程序中的视频。该应用程序仅是纵向的,但视频可以旋转。播放视频后,应用程序以纵向模式返回。我可以评价,但在“完成”视频播放器按钮单击横向模式下的视图返回后。

我怎样才能解决这个问题?

非常感谢。

4

2 回答 2

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

  2. 单击项目,然后单击目标。在部署信息下的常规类别中启用所有轮换

  3. 现在打开您的 Root 视图控制器并放入以下行。给出您的应用程序的方向

代码:

-(BOOL)shouldAutorotate
{
    return TRUE;
}

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

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

于 2014-02-19T12:19:11.470 回答
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];
    }

希望能帮助到你。

于 2014-02-19T11:45:23.167 回答