美文网首页
iOS截屏分享

iOS截屏分享

作者: rayChow | 来源:发表于2017-02-14 15:41 被阅读264次

类似长图截屏分享的功能
把整个view给完整的截下来,做成一张图片。

-(UIImage *)getImageWithFullScreenshot   
{    
    BOOL ignoreOrientation = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0");    
        
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;    
        
    CGSize imageSize = CGSizeZero;    
    if (UIInterfaceOrientationIsPortrait(orientation) || ignoreOrientation)    
        imageSize = [UIScreen mainScreen].bounds.size;    
    else    
        imageSize = CGSizeMake([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);    
        
    UIGraphicsBeginImageContextWithOptions(imageSize, NO, [UIScreen mainScreen].scale);    
    CGContextRef context = UIGraphicsGetCurrentContext();    
        
    for (UIWindow *window in [[UIApplication sharedApplication] windows])    
    {    
        CGContextSaveGState(context);    
        CGContextTranslateCTM(context, window.center.x, window.center.y);    
        CGContextConcatCTM(context, window.transform);    
        CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y);    
            
        // Correct for the screen orientation    
        if(!ignoreOrientation)    
        {    
            if(orientation == UIInterfaceOrientationLandscapeLeft)    
            {    
                CGContextRotateCTM(context, (CGFloat)M_PI_2);    
                CGContextTranslateCTM(context, 0, -imageSize.width);    
            }    
            else if(orientation == UIInterfaceOrientationLandscapeRight)    
            {    
                CGContextRotateCTM(context, (CGFloat)-M_PI_2);    
                CGContextTranslateCTM(context, -imageSize.height, 0);    
            }    
            else if(orientation == UIInterfaceOrientationPortraitUpsideDown)    
            {    
                CGContextRotateCTM(context, (CGFloat)M_PI);    
                CGContextTranslateCTM(context, -imageSize.width, -imageSize.height);    
            }    
        }    
            
        if([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])    
            [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];    
        else    
            [window.layer renderInContext:UIGraphicsGetCurrentContext()];    
            
        CGContextRestoreGState(context);    
    }    
        
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();    
        
    UIGraphicsEndImageContext();    
        
    return image;    
}  

相关文章

  • flutter:截屏

    1.flutter-截屏组件 2.flutter-截屏插件 3.flutter-iOS原生截屏 iOS代码 4.获...

  • (最新)iOS截屏

    ios webview 截屏:ios截屏 前言:介绍一下截屏有很多种做法1:截当前屏幕内容2:截整个视图的所有内容...

  • iOS截屏分享

    类似长图截屏分享的功能把整个view给完整的截下来,做成一张图片。

  • ios截屏

    ios截屏

  • 针对WKWebView进行内容的截屏。

    最近项目中需要截屏分享的功能,之前也了解过iOS截屏的技术,并写了关于截屏的笔记,兴冲冲的拿着代码稍作修改,对WK...

  • iOS 系统自带截屏分享

    分享一篇iOS系统自带截屏分享 使用方案 简单粗暴,贴上代码

  • “监听用户截屏”弹出分享窗口

    从 iOS 7 开始,苹果提供了监听用户截屏操作的通知: 我们可以使用这个通知来做例如:截屏弹出分享窗口的功能。

  • iOS 应用内截屏分享

    需求:捕获用户截屏操作,并建议用户截屏后的操作。虽然iOS11 有系统的截屏,但 APP 内截屏可便捷操作。 封装...

  • iOS 截屏&长截屏

    截屏在 iOS 开发中经常用到,本篇文章讲的是监听用户截屏操作,并且获取截屏图片,如果当前是UIScrollVie...

  • 今日头条

    截屏分享

网友评论

      本文标题:iOS截屏分享

      本文链接:https://www.haomeiwen.com/subject/sbgxwttx.html