UIWebView不会缩放内容以适应

问题描述:

我有一个webview,它是层次结构中的顶层窗口,并且已声明如下所示。但是,它不会缩放页面以适应。虽然scalesPageToFit属性设置为YES,但页面左上角对齐,但未缩放。任何帮助将不胜感激。

I have a webview which is the top window in the hierarchy and has been declared as shown below. However, it does not scale pages to fit. Pages are top left aligned, but are not scaled, despite the scalesPageToFit property being set to YES. Any help would be greatly appreciated.

webLookupView = [[UIWebView alloc] initWithFrame:CGRectMake(16, 63, 289, 327)];
webLookupView.backgroundColor = [UIColor lightGrayColor];
webLookupView.dataDetectorTypes = UIDataDetectorTypeAll;
webLookupView.scalesPageToFit = YES;


我后来发现某些网页已正确缩放,但有些不是。对于未正确缩放的网页,javascript可用于控制缩放,如下所示:

I have subsequently discovered that some web pages are correctly scaled, but some are not. For web pages which are not properly scaled, javascript can be used to control zooming as follows:

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