2013-04-06 65 views
1

我正在使用小型UIWebView,并且scalesPageToFit对某些网址无法正常工作。 (看上去像是以100%无法改变(但如果我缩小手动的WebView(手势),它的工作UIWebview scalesPageToFit无法正常工作

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]; 
    } 
} 

任何想法?谢谢!

+0

的[UIWebView的不结垢内容以适合]可能重复(http://stackoverflow.com/questions/1511707/uiwebview-does-没有规模化内容,以配合) – 2014-10-10 11:44:51

回答

0

在一些这种类型的问题产生的情况下,当时的Java脚本的使用为UIWebView变焦,使用下面的代码的控制。

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

另一种方式是

请参阅此回答UIWebView does not scale content to fit