【问题标题】:UIWebview scalesPageToFit doesn't work perfectlyUIWebview scalesPageToFit 不能完美运行
【发布时间】:2013-04-06 19:47:23
【问题描述】:

我正在使用一个小的UIWebView,而scalesPageToFit 对于某些网址无法正常工作。 (看起来它无法以 100% 调整大小。(但如果我手动缩小 web 视图(手势),它可以工作!

view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200.0f, 400.0f)];
webViewT = [[UIWebView alloc] initWithFrame:view.bounds];
webViewT.delegate = self;
webViewT.scalesPageToFit = YES;
NSURL* url = [NSURL URLWithString:@"http://www.google.com/"];
[webViewT loadRequest:[NSURLRequest requestWithURL:url]];

请注意,我找到了解决方案:(下面的工作,但我有时间看到“调整大小”

- (void) webViewDidFinishLoad:(UIWebView *)webViewT {  
    if ([theWebView respondsToSelector:@selector(scrollView)])
    {
        UIScrollView *scroll=[theWebView scrollView];

        float zoom=theWebView.bounds.size.width/scroll.contentSize.width;
        [scroll setZoomScale:zoom animated:NO];
    }
}

有什么想法吗?谢谢!

【问题讨论】:

标签: iphone ios objective-c xcode


【解决方案1】:

在某些情况下会产生此类问题。当时用java脚本控制UIWebView的Zoom,使用如下代码。

NSString *jsCommand = [NSString stringWithFormat:@"document.body.style.zoom = 1.5;"];
[webLookupView stringByEvaluatingJavaScriptFromString:jsCommand];

其他方式是

参考这个答案UIWebView does not scale content to fit

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-18
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 1970-01-01
    • 2014-12-05
    • 2012-09-18
    相关资源
    最近更新 更多