首页 文章

完成电影播放器上的完成后恢复为肖像?

提问于
浏览
1

我有一个MPMoviePlayer工作 . 它旨在将邮资大小的电影显示为视图中的子视图 . 当手机旋转为横向时,它将进入全屏模式 . 当手机处于人像状态时,它会进入邮票图像模式 .

唯一的问题是当我在横向模式下按Done时,它会保留在风景中,带有邮票大小的电影,而不是重新开始画像 .

这是我的一些代码:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 


    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation ==  UIInterfaceOrientationLandscapeLeft) {
        [moviePlayerController setFullscreen:YES animated:YES];
    } else
    {
        [moviePlayerController setFullscreen:NO animated:YES];

    }


}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

        return interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft;

}

按完成后如何让它进入纵向模式?

4 回答

  • 0

    @cannyboy ...如果您的应用程序仅适用于纵向模式,您只需在APPDelegate.m中使用以下方法

    - (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if ([[window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
    {
        //NSLog(@"in if part");
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else
    {
        //NSLog(@"in else part");
        return UIInterfaceOrientationMaskPortrait;
    }}
    
  • 2

    我是同样的问题,现在我告诉你我是如何解决它的 . 我不知道下面的方法是对还是错,但它工作正常 .

    • 而不是在视图中打开 MPMoviePlayer 而不是在新的_2580785中打开它 . 我的意思是创建一个新的 UIViewController 来显示电影并将它推到一些如何使用户不会理解他们正在重定向到新的屏幕 .

    • 禁用横向模式的父屏幕并允许 MovieViewController 进行横向显示 .

    • 当用户按下完成按钮或关闭按钮时, viewController 和之前的屏幕不支持横向模式,因此屏幕将自动以纵向模式显示 .

  • 1
    [[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(_moviePlayerWillExitFullscreen:)
                                             name:MPMoviePlayerWillExitFullscreenNotification object:nil];
    
    
    - (void)_moviePlayerWillExitFullscreen:(NSNotification *)notification 
    {
        CGFloat ios = [[[UIDevice currentDevice] systemVersion] floatValue];
        CGFloat min = 5.0;
        if (ios >= min)
        {
            if (self.interfaceOrientation != UIInterfaceOrientationPortrait)
            {  
                if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait])
                {
                    [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
                    [self willRotateToInterfaceOrientation:self.interfaceOrientation duration:0];
                    [UIViewController attemptRotationToDeviceOrientation];
                } 
            }
        }   
    }
    

    请注意,这仅适用于ios 5.0及更高版本,并且您将收到不支持setOrientation的警告,但它运行良好

  • -1

    您可以尝试的一种方法是强制您的设备认为它处于纵向模式 . 为此,请尝试使用:

    [[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
    

    如果您不希望您的设备在不播放电影时显示横向,则还必须在上面显示的代码中添加一些逻辑,以便仅在播放电影时更改为横向 .

相关问题