【问题标题】:How to display UIWebView with correct zoom scale in landscape如何在横向中以正确的缩放比例显示 UIWebView
【发布时间】:2011-08-14 15:07:23
【问题描述】:

我创建 UIWebView 并像这样设置自动旋转:

- (void)loadView
{
    self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)] autorelease];

    UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
    webview.delegate = self;
    webview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_darkgreen_320x312.png"]];
    webview.dataDetectorTypes = UIDataDetectorTypeLink;
    webview.multipleTouchEnabled = YES;
    webview.scalesPageToFit = YES;
    webview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [webview loadHTMLString:@"<meta name=\"viewport\" content=\"width=320\">content ..." baseURL:nil];
    [self.view addSubview:webview];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

当我在横向旋转它而不缩放它时它工作得很好。它会在两个旋转时全屏显示。

问题是,如果我在纵向模式下缩小或稍微放大,然后在横向模式下旋转它,webview 仍然会以与纵向模式相同的大小进行缩放,并且它具有如图中的黑色空间 > http://cl.ly/1o3c4712053C3T2C2H2z

它的横向宽度是正确的,480px(你可以看到它的滚动条在屏幕的最右边)。我不明白为什么 webview 不显示全屏。

我做错了什么? 有没有什么办法解决这一问题? 请帮忙。

提前致谢。

【问题讨论】:

  • 这个问题你解决了吗??
  • 我发现其他应用也有这个问题(比如Facebook)。我认为这是苹果的错误......?
  • 有同样的问题-问题在这个线程中解决了:stackoverflow.com/questions/2890673/…

标签: iphone uiwebview zooming rotation


【解决方案1】:

为了达到您的效果,您需要在旋转时将 zoomScale 设置为 0。在这里查看我的完整答案:UIWebView content not adjusted to new frame after rotation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-07
    • 2015-09-09
    相关资源
    最近更新 更多