【问题标题】:How to zoom webView with pdf file如何使用 pdf 文件缩放 webView
【发布时间】:2011-07-20 07:38:03
【问题描述】:

如何放大 UIWebView。

我从 UIWebView 的资源包中加载了 pdf 文件。

现在尝试缩放 web 视图。所以它会对pdf文件产生缩放效果。

所以。

如何缩放 UIWebView。

任何示例。请帮帮我。

【问题讨论】:

    标签: objective-c ipad


    【解决方案1】:

    只需使用以下代码:

    self.pdfviewwebview.scalesPageToFit = YES;
    self.pdfviewwebview.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    self.pdfviewwebview.delegate = self;
    

    这里大多数人忘记的最棘手的事情是设置 webview 的委托,所以要小心。

    【讨论】:

    • @Gary Davies 它是 UIViewController 子类,它正在实现协议
    【解决方案2】:
    UIWebView *tempWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height)];  
    tempWebView.backgroundColor = [UIColor whiteColor];  
    **tempWebView.scalesPageToFit = YES; //this enables the zooming**
    tempWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    tempWebView.delegate = self;
    [self.view addSubview:tempWebView]; 
    [self setWebView:tempWebView];
    
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"your_file" ofType:@"pdf"];
    NSURL *targetURL = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
    [self.webView loadRequest:request];
    

    【讨论】:

      【解决方案3】:

      按住 Option 键可以模拟捏合缩放手势。在您的模拟器上,将出现两个灰色圆圈,表示它正在模拟多点触控、捏合缩放手势。

      【讨论】:

      • 它的捏缩放...我做了 webview.delegate=self;和 webview.scalesPageToFit=YES; webView.multipleTouchEnabled=YES;并将其添加到视图 self.view addsubview 这已经完成但是......缩放功能不起作用。
      猜你喜欢
      • 2019-06-16
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-24
      • 2011-04-01
      相关资源
      最近更新 更多