问题: 长图截屏分享(超出一个屏幕的view分享) 今天为了做一个类似长图截屏分享的功能,局限性再与截屏的时候,只能把当前屏幕所看见的部分给截下来,如果这个ViewController很长,不能一页显示不全,我想把这个页面分享出去,要分享全部的,完整的页面,别人看上去才有意义,除此外,用文字,用链接,都不好使,仅仅要的就是把整个view给完整的截下来,做成一张图片。 解决方案: 将这个view,直接转成uiimage.然后分享的时候,就直接把分享的图片,设置成为这张imageView.但是要注意的是,使用友盟分享的时候,需要注意截图的大小,太大了,可能分享不成功。 [objc] view plain copy <pre name="code" class="objc">-(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; } 第三方sdk: 点击打开链接 关于分享的代码: 我这儿就不贴了: