【问题标题】:UIWebview fitting to screen but not zooming in iphone programmingUIWebview 适合屏幕但不能放大 iphone 编程
【发布时间】:2013-03-12 06:57:35
【问题描述】:

我正在开发 uiwebview,它应该加载来自服务器的动态 url。 我想在我的 iPhone 应用程序中显示它适合 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;

请告诉我如何在不丢失放大/缩小功能的情况下实现适合 iphone 屏幕尺寸的 webview。

提前致谢。

【问题讨论】:

    标签: iphone ios objective-c


    【解决方案1】:

    使用以下代码

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

    【讨论】:

      【解决方案2】:

      问题可能出在这一行: aWebView.frame = self.view.bounds;

      为什么在将 webview 添加到 m_pView 时设置 self.view 的边界?

      【讨论】:

      • 你认为它与webview的缩放有什么关系吗?我尝试设置 aWebView.frame = self.m_pView.bounds;而且还没有效果。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多