【问题标题】:ios, Youtube full screen in a webview is rotatingios,webview中的Youtube全屏正在旋转
【发布时间】:2011-12-29 00:14:52
【问题描述】:

我正在开发一个应用程序,我想在页面中添加一个 youtube 视频。 它适用于以下代码:

-(void)viewDidLoad{
    [super viewDidLoad];

}

- (void) viewWillAppear:(BOOL)animated {
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.47 green:.43 blue:.4 alpha:1];

}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    //return (interfaceOrientation == UIInterfaceOrientationPortrait);
    NSString *htmlString;
    if(interfaceOrientation == UIInterfaceOrientationPortrait){
        htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 20\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"768\" height=\"960\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"768\" height=\"960\"></embed></object></div></body></html>",urlToOpen,urlToOpen];

    }else{
        htmlString = [NSString stringWithFormat:@"<html><head><meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 212\"/></head><body style=\"background:#F00;margin-top:0px;margin-left:0px\"><div><object width=\"1024\" height=\"704\"><param name=\"movie\" value=\"%@\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"1024\" height=\"704\"></embed></object></div></body></html>",urlToOpen,urlToOpen];

    }
    [self.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];
    return  YES;
}

视图在纵向和横向上都可以正常工作。 问题是当我看到全屏视频并旋转时。当我完成全屏时,webview 没有检测到旋转并将 webview 打印为错误的方式。

我如何检测到 Youtube 全屏正在旋转以旋转我的视图?

谢谢

【问题讨论】:

    标签: ios uiwebview youtube fullscreen landscape-portrait


    【解决方案1】:

    将内容宽度设置为 100%

    我的模板

    <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \
    <html xmlns=\"http://www.w3.org/1999/xhtml\"> <head> \
    <meta name=\"viewport\" content=\"width=320\"> \
    <style> \
    html,body {-webkit-text-size-adjust: none; size:100%%} \
    body {margin: 0; padding: 0;width:100%;} \
    table { font-family:Georgia; font-size:%dpt; border-style: none; size:100%%} \
    </style> </head>
    

    ....

    【讨论】:

      【解决方案2】:

      我假设您已经处理了方向回调? (shouldAutorotateToInterfaceOrientation, didRotateFromInterfaceOrientation)

      当 YouTube 视频结束并且焦点返回到您的应用时,应调用 viewWillAppear 方法。在那里,您可以获取设备方向:

      UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
      

      然后执行您的布局更改。这也将在此视图首次打开时处理布局。

      你可以在 switch 语句中做到这一点:

      switch(orientation) {
          case UIInterfaceOrientationLandscapeLeft:  //layout for this landscape mode
          case UIInterfaceOrientationPortraitUpsideDown:  //layout for this portrait mode
      

      【讨论】:

      • 谢谢,但它也不是真正正确的。 youtube 全屏是当用户按下使视频与屏幕一样大的两个箭头时。然后,当你用这个全屏旋转并按下“完成”时,屏幕保持原来的方向。未调用 viewWillAppear。
      【解决方案3】:

      我像这样使用 NSNotification 处理了这个问题

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

      将被调用的方法是

      - (void)moviePlayerDidExitFullScreen
      {
          UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
      
          if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationPortraitUpsideDown) 
          {
              [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
          }
      }
      

      希望有帮助

      【讨论】:

      • 使用私有 API 可能会破坏您的应用程序或导致拒绝。
      • 私有 API ?你能看到上面的任何私有 api 用法吗?
      • UIMoviePlayerControllerDidExitFullscreenNotification 没有在任何地方记录。因此,它可以在操作系统更新中进行更改...此外,使用未记录的通知可能会导致拒绝。
      • 我的应用程序正在 appstore 上运行,顺便说一句,如果你有更好的方法,请告诉我?
      • 这行得通吗?是不是私有API??谢谢
      猜你喜欢
      • 2012-03-03
      • 1970-01-01
      • 2017-06-15
      • 2012-05-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-21
      • 2019-02-14
      • 1970-01-01
      相关资源
      最近更新 更多