Ios UIWebView嵌入式YouTube视频播放上的状态栏问题

Ios UIWebView嵌入式YouTube视频播放上的状态栏问题,ios,video,uiwebview,youtube,Ios,Video,Uiwebview,Youtube,播放youtube视频如下: videoView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 50, 300, 215)]; videoView.backgroundColor = [UIColor clearColor]; videoView.opaque = NO; videoView.delegate = self; [self.view addSubview:videoView]; NSURLRequest *loadRequest

播放youtube视频如下:

videoView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 50, 300, 215)];
videoView.backgroundColor = [UIColor clearColor];
videoView.opaque = NO;
videoView.delegate = self;
[self.view addSubview:videoView];
NSURLRequest *loadRequest=[NSURLRequest requestWithURL:Your_Youtube_URL];
[videoView loadRequest:loadRequest];
- (void)viewDidLoad
{
…

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(VideoExitFullScreen:)
                                                 name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                               object:nil];

}

- (void)viewDidUnload
{

…

[[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                                  object:nil];
}

- (void)VideoExitFullScreen:(id)sender{

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];

}
问题:UIWebView嵌入式YouTube视频播放上的状态栏问题

生成状态栏问题的步骤:

videoView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 50, 300, 215)];
videoView.backgroundColor = [UIColor clearColor];
videoView.opaque = NO;
videoView.delegate = self;
[self.view addSubview:videoView];
NSURLRequest *loadRequest=[NSURLRequest requestWithURL:Your_Youtube_URL];
[videoView loadRequest:loadRequest];
- (void)viewDidLoad
{
…

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(VideoExitFullScreen:)
                                                 name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                               object:nil];

}

- (void)viewDidUnload
{

…

[[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                                  object:nil];
}

- (void)VideoExitFullScreen:(id)sender{

    [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];

}
  • 当应用程序方向支持仅为纵向时

  • 用户单击在UIWebview嵌入式youtube视频播放器上播放视频

  • 设备打开其默认视频播放器以播放视频,并提供横向支持以播放视频,即使您的应用程序只有方向支持

  • 现在,用户将设备方向更改为横向,以便全屏观看视频 


  • 现在用户按下“完成”按钮停止视频并返回应用程序

  • 在这种情况下,状态栏保持横向,应用程序屏幕显示为纵向模式


    • 解决方案:

      videoView = [[UIWebView alloc] initWithFrame:CGRectMake(10, 50, 300, 215)];
      videoView.backgroundColor = [UIColor clearColor];
      videoView.opaque = NO;
      videoView.delegate = self;
      [self.view addSubview:videoView];
      NSURLRequest *loadRequest=[NSURLRequest requestWithURL:Your_Youtube_URL];
      [videoView loadRequest:loadRequest];
      
      - (void)viewDidLoad
      {
      …
      
      [[NSNotificationCenter defaultCenter] addObserver:self
                                                   selector:@selector(VideoExitFullScreen:)
                                                       name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                                     object:nil];
      
      }
      
      - (void)viewDidUnload
      {
      
      …
      
      [[NSNotificationCenter defaultCenter] removeObserver:self
                                                          name:@"UIMoviePlayerControllerDidExitFullscreenNotification"
                                                        object:nil];
      }
      
      - (void)VideoExitFullScreen:(id)sender{
      
          [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
      
      }