【问题标题】:Reverting to portrait after Done pressed on movie player?在电影播放器​​上按下完成后恢复为纵向?
【发布时间】:2011-09-13 19:45:54
【问题描述】:

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

唯一的问题是当我在横向模式下按完成时,它会保持横向,与邮票大小的电影,而不是踢回纵向..

这是我的一些代码:

-(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;

}

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

【问题讨论】:

    标签: iphone objective-c ios mpmovieplayercontroller


    【解决方案1】:

    @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;
    }}
    

    【讨论】:

    • 如果我使用此代码,除了一件重要的事情外,一切正常 - 当我在横向模式下单击“完成”按钮时,在视频播放器关闭后,我也会在横向模式下看到我的视图控制器。跨度>
    • 请让我知道你已经评论了除了这个与方向相关的所有代码吗?如果没有,请评论它在这里工作正常。
    • 谢谢,终于成功了!我错过了一行代码,将其删除 - 一切都很好!我会在 6 小时内给你赏金。
    • 谢谢,我会等待这个享受eeee :)
    【解决方案2】:

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

    • 不要在视图中打开MPMoviePlayer,而是在新的viewController 中打开它。我的意思是创建一个新的UIViewController 来显示电影并以某种方式推送它,这样用户就不会明白他们正在重定向到新屏幕。
    • 禁用横向模式的父屏幕并允许MovieViewController横向模式。
    • 当用户按下完成按钮或关闭按钮时,只需pop viewController 并且由于前一个屏幕不支持横向模式,因此屏幕将自动以纵向模式显示。

    【讨论】:

    • 您不需要创建新的视图控制器请查看我的以下答案。
    【解决方案3】:
    [[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 的警告,但效果很好

    【讨论】:

      【解决方案4】:

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

      [[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
      

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

      【讨论】:

      • 不要使用该方法,它是无证的并且是私有 API 的一部分 - 因此被拒绝的原因。
      猜你喜欢
      • 1970-01-01
      • 2011-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多