【问题标题】:iOS7 viewController and MPMoviePlayerViewController RotationiOS7 viewController 和 MPMoviePlayerViewController 旋转
【发布时间】:2014-03-19 17:06:17
【问题描述】:

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

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

我该如何解决这个问题?

非常感谢。

【问题讨论】:

标签: ios objective-c uiviewcontroller rotation mpmoviewcontroller


【解决方案1】:
  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,则将方向方法添加到该控制器

【讨论】:

  • 嗯,所以,如果我要在 HomeVC 中创建肖像,我可以使用 [self performSegueWithIdentifier:@"myIdentifiew" sender:self]; 并设置 - (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait; }。但是当我有横向播放器时,我必须做什么?谢谢
  • 这没有问题,但请确保将方向方法设置为从您的视频播放 vc 开始的那个 vc。
  • 成功!!!它有效:D 我在@interface myPlayerViewController : MPMoviePlayerViewController 的每个 VC 中添加了 supportedInterfaceOrientations 肖像。如果用户在播放器中按下“完成”按钮,我以前的 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];
    }

希望对你有帮助。

【讨论】:

  • 谢谢,这对我有帮助,+1!但是我必须编辑一些导航栏和状态栏的代码才能得到一个好的结果。在标记为正确答案之前,我会尝试其他解决方案。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多