xcode UIWebview scalesPageToFit 不能完美运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15855291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UIWebview scalesPageToFit doesn't work perfectly
提问by Franck
I'm using a small UIWebView
, and scalesPageToFit
doesn't work correctly for some url. (look like it cannot resize at 100%. (but if i zoom out the webview manually(gesture), it work!
我正在使用一个小的UIWebView
,并且scalesPageToFit
对于某些 url 无法正常工作。(看起来它不能 100% 调整大小。(但如果我手动缩小 webview(手势),它工作!
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]];
Please note that i've found a solution:(below work, BUT I have the time to see a "resize"
请注意,我找到了一个解决方案:(下面的工作,但我有时间看到“调整大小”
- (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];
}
}
Any idea? Thanks!
任何的想法?谢谢!
回答by iPatel
In Some of cases this types of problem Generated. At that time java script use for control of Zoom of UIWebView
, use following code.
在某些情况下会产生这种类型的问题。当时java脚本用于控制Zoom的UIWebView
,使用以下代码。
NSString *jsCommand = [NSString stringWithFormat:@"document.body.style.zoom = 1.5;"];
[webLookupView stringByEvaluatingJavaScriptFromString:jsCommand];
Other way is
另一种方式是
Refer this Answer UIWebView does not scale content to fit
请参阅此答案UIWebView 不会缩放内容以适合