【问题标题】:UIWebView does not cover entire view in landscape modeUIWebView 在横向模式下不覆盖整个视图
【发布时间】:2012-11-28 17:58:49
【问题描述】:

我正在开发一个 iPad 应用程序,当用户通过登录表单进行身份验证时,它将以模态方式在 UIWebView 中加载网页。这很好用,但是当我将设备旋转到横向模式时,webview 只覆盖了 75% 的屏幕:

这是来自我的登录视图控制器的代码:

    // Load storyboard for easy instatiation of the login view controller
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];
    WebViewController *webController =
    (WebViewController *)[storyboard instantiateViewControllerWithIdentifier:@"WebView"];

    // Present the embedded browser in fullscreen.
    [webController setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:webController animated:YES completion: nil];

【问题讨论】:

  • 注意,如果你的app只做这个(登录后显示一个UIWebView),提交到App Store会被Apple拒绝。

标签: ios ipad uiwebview landscape


【解决方案1】:

您使用的是约束还是自动调整大小的蒙版?如果没有,您可能需要使用它们并确保 Web 视图覆盖整个视图的框架。

【讨论】:

  • @Debopam - 从 iOS 6 开始,您现在可以使用 SDK 提供的自动布局功能。
【解决方案2】:

您所要做的就是在您的WebViewController-shouldAutorotateToInterfaceOrientation 方法中为横向定义UIWebView 的框架。

事情是这样的,

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

 if(toInterfaceOrientation == UIInterfaceOrientationPortrait)
 {
     webView.frame = CGRectMake (0, 0 768, 1024);
 }
 else 
 {
     webView.frame = CGRectMake (0, 0 1024, 768);
 }
 return YES;
}

【讨论】:

  • 感谢您的回答,但令人惊讶的是它没有任何效果。我认为 UIWebView 的大小调整会在旋转时自动进行。
  • 啊...我没有看到您正在为 iOS 6 构建此应用程序。好吧,iOS 6 不推荐使用 -shouldAutorotateToInterfaceOrientation 方法,这就是它不起作用的原因,正如@lostInTransit 所说的自动调整大小会做的。
【解决方案3】:
  1. 使用 webView 代理 2.包括这个方法
    • (void)webViewDidFinishLoad:(UIWebView *)webView { [self.webView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; }
      }
  2. 也包括这个

    • (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 持续时间:(NSTimeInterval)duration { [self.webView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 2013-03-23
    • 2011-09-05
    • 1970-01-01
    • 1970-01-01
    • 2011-12-28
    相关资源
    最近更新 更多