2013-03-12 74 views
1

我正在uiwebview上工作,它應該加載來自服務器的動態URL。 我想在iPhone應用程序中顯示它適合iPhone的屏幕尺寸,並且它應該放大和縮小。我使用它UIWebview適合屏幕,但不能放大iphone編程

代碼是:

m_pView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 430)]; 
    m_pView.backgroundColor = [UIColor blackColor]; 
    self.view = m_pView; 

UIWebView *aWebView = [[[UIWebView alloc] initWithFrame:CGRectMake(0, 1, 320, 400)] autorelease]; 
    aWebView.dataDetectorTypes = UIDataDetectorTypeNone; 
    aWebView.delegate = self; 
    NSString* url = [NSString stringWithFormat: @"http://%@",[m_URL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 
    aWebView.scalesPageToFit = YES; 
    aWebView.autoresizesSubviews = YES; 
    aWebView.frame = self.view.bounds; 

    NSURL *aURL = [NSURL URLWithString: url]; 
    NSURLRequest *aRequest = [NSURLRequest requestWithURL:aURL]; 
    //load the index.html file into the web view. 
    [aWebView loadRequest:aRequest]; 
    [m_pView addSubview:aWebView]; 
    self.m_webView = aWebView; 

請讓我知道是怎麼實現的WebView安裝到iPhone的屏幕尺寸,而不輸入/輸出功能失去變焦。

在此先感謝。

回答

0

使用下面的代碼

yourWEbView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    yourWEbView.contentMode = UIViewContentModeScaleAspectFit; 
+0

我試過這個,不適合我 – iphonedeveloper 2013-03-12 09:46:27

0

問題可能是在這一行: aWebView.frame = self.view.bounds;

爲什麼你要在爲m_pView添加webview的同時設置self.view的邊界?

+0

你認爲它與webview的縮放有任何關係?我嘗試設置一個WebView.frame = self.m_pView.bounds;並沒有效果。 – iphonedeveloper 2013-03-13 06:06:02