2013-04-06 63 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