【问题标题】:Rotate youtube video with iOS8使用 iOS8 旋转 youtube 视频
【发布时间】:2015-01-15 22:30:32
【问题描述】:

我在旋转 youtube 视频时遇到问题。我将以下代码添加到我的应用程序中。它适用于 iOS 7。但是,它不适用于 iOS8。

在我的视图控制器中,我使用了以下代码:

     if(IS_OS_6_OR_LATER){ 
        // I use the following notification for iOS 7
      [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) latername:@"UIMoviePlayerControllerDidEnterFullscreenNotification" object:nil];//Notification

     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];//Notification
                }    



if (IS_OS_8_OR_LATER) { 
// I use the following notification for iOS 8
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeStarted:) name:UIWindowDidBecomeVisibleNotification object:self.view.window];
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youTubeFinished:) name:UIWindowDidBecomeHiddenNotification object:self.view.window];
        }



 -(void) youTubeStarted:(NSNotification*) notif {
    //Handle event 
            AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
            appDelegate.fullScreenVideoIsPlaying = YES;
            NSLog(@"start fullscreen");
        }
        -(void) youTubeFinished:(NSNotification*) notif {
            AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];//Notification
            appDelegate.fullScreenVideoIsPlaying = NO;//Notification
            NSLog(@"exit fullscreen");//Notification
        }



 -(BOOL) shouldAutorotate {
    //Handle rotate
            NSLog(@"AutoState");
            return NO;
        }
        -(NSUInteger)supportedInterfaceOrientations{
    //Handle rotate
            NSLog(@"AutoState 1");
            return UIInterfaceOrientationMaskPortrait;//Notification
        }
        - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    //Handle rotate
            NSLog(@"AutoState 2");
            return UIInterfaceOrientationPortrait;//Notification
        }

在 iOS 7 中,当视频在横向模式下播放时,我按下完成按钮,我看到日志“AutoState 1”显示,但是在 iOS 8 上运行时我没有看到此日志。你能帮我解决这个问题吗iOS 8?非常感谢

【问题讨论】:

  • 请花时间正确格式化您的代码,以便于阅读。提供有关您的问题及其背景的更多信息。
  • @gareththegeek:对不起,因为我是新手。对此我感到非常抱歉
  • 谁能帮帮我?请!!!!!!!
  • 任何人!!!!帮助!!!!!!!!!!!!!!!!

标签: uiwebview rotation ios8 ios8.1


【解决方案1】:

与其将整个应用程序限制为纵向模式,然后尝试让视频播放器允许横向模式,不如在整个应用程序中允许横向模式,然后将您的单个视图控制器(或根视图控制器)限制为仅允许纵向模式,像这样:

在目标设置中,允许您的应用使用横向:

在您的视图控制器中,添加此项以将其限制为纵向:

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-08
    • 2011-07-08
    • 2011-04-25
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多