首页 文章

将横向中的MPmovieViewController仅以纵向方式解除视图时出错(UIApplicationInvalidInterfaceOrientation)

提问于
浏览
0

我正在为大多数视图中的肖像模式工作的IOS7创建一个xcode应用程序 .

项目设置允许“纵向”“向左横向”和“向右横向” .

在我只想以纵向显示的视图中,我添加以下代码以纵向模式锁定它们:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

在其中一个锁定视图中,我使用以下代码呈现MPmovieViewController:

MPMoviePlayerViewController *movieViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:replayURL];
    movieViewController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

    [self presentMoviePlayerViewControllerAnimated:movieViewController];

这段代码创建了一个可以在Portrait和Landscape中使用的MPmovieViewController . (这就是我想要的)

当我在横向模式下按下MPMovieViewController的完成按钮以关闭MovieController时,会出现问题 . 上一个视图不支持横向模式,因此我有以下错误:

*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'

当关闭MPMovieViewController时,如何强制旋转回到纵向模式?

最好的祝福

理查德

1 回答

  • 2

    我在回答自己 . 实际上它非常简单 .

    只需添加到仅限纵向视图:

    -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; }
    

    谢谢

相关问题