如何在横向显示具有正确缩放比例的 UIWebView

发布于 2024-11-04 00:41:47 字数 1293 浏览 3 评论 0原文

我创建 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 不显示全屏。

我做错了什么? 有什么办法可以解决这个问题吗? 请帮忙。

提前致谢。

I create UIWebView and set autorotate like this:

- (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);
}

It works perfectly when I rotate it in landscape without zooming. It will display full screen on both rotation.

The problem is if I zoom-out or a little bit zoom-in in portrait mode and then rotate it in landscape, webview still zoom with the same size of portrait mode and it has black space like in picture > http://cl.ly/1o3c4712053C3T2C2H2z

It's width in landscape is correct, 480px (you can see its scrollbar is on most right of screen). I don't understand why webview don't display full screen.

What I do wrong?
Is there any way to fix this?
Please help.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪冰清 2024-11-11 00:41:47

为了达到您的效果,您需要在旋转时将 ZoomScale 设置为 0。请在此处查看我的完整答案: UIWebView 内容未调整旋转后到新框架

In order to achieve your effect you need to set the zoomScale to 0 on rotation. See my full answer here: UIWebView content not adjusted to new frame after rotation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文