【问题标题】:Is it possible to capture a screenshot of a whole webpage in the iOS Simulator?是否可以在 iOS 模拟器中捕获整个网页的屏幕截图?
【发布时间】:2014-01-03 19:40:24
【问题描述】:

目前我正在制作“传统”屏幕截图,并使用图形编辑器将它们组合起来以一次显示完整的网页。有没有更有效的方法来截取整个网页,就像使用谷歌浏览器的Awesome Screenshot 一样?

(不,我没有 iPhone;)

【问题讨论】:

    标签: ios iphone objective-c ios-simulator webpage-screenshot


    【解决方案1】:

    你必须自己写。

    1. 在您的应用中创建一个全屏webView
    2. 打开要打开的页面
    3. 操作webView.scrollView属性成功移动到页面底部。
    4. 每次都截屏
    5. 如果您在底部,请将屏幕截图合并为一张大图。

    我相信这是最简单的方法,可以在模拟器上运行。

    【讨论】:

    • 我没有开发移动应用程序的经验,我只想测试一个网站而不是移动应用程序。但是,如果您的解决方案有效,您可以为此目的开发一个应用程序。
    【解决方案2】:

    请看下面的代码。

    -(NSData *)getImageFromView:(UIView *)view  // Mine is UIWebView but should work for any
    {
        NSData *pngImg;
        CGFloat max, scale = 1.0;
        CGSize viewSize = [view bounds].size;
    // Get the size of the the FULL Content, not just the bit that is visible
    CGSize size = [view sizeThatFits:CGSizeZero];
    
    // Scale down if on iPad to something more reasonable
    max = (viewSize.width > viewSize.height) ? viewSize.width : viewSize.height;
    if( max > 960 )
        scale = 960/max;
    
    UIGraphicsBeginImageContextWithOptions( size, YES, scale );
    
    // Set the view to the FULL size of the content.
    [view setFrame: CGRectMake(0, 0, size.width, size.height)];
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:context];    
    pngImg = UIImagePNGRepresentation( UIGraphicsGetImageFromCurrentImageContext() );
    
    UIGraphicsEndImageContext();
    return pngImg;    // Voila an image of the ENTIRE CONTENT, not just visible bit
    

    }

    我从this 链接获得此代码。希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-25
      • 1970-01-01
      • 1970-01-01
      • 2019-01-31
      • 2012-04-17
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多