2013-03-12 39 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