iOS 如何把view转成image,截屏分享/ 整个视图的分享。

问题: 长图截屏分享(超出一个屏幕的view分享)

今天为了做一个类似长图截屏分享的功能,局限性再与截屏的时候,只能把当前屏幕所看见的部分给截下来,如果这个ViewController很长,不能一页显示不全,我想把这个页面分享出去,要分享全部的,完整的页面,别人看上去才有意义,除此外,用文字,用链接,都不好使,仅仅要的就是把整个view给完整的截下来,做成一张图片。


 解决方案: 

       将这个view,直接转成uiimage.然后分享的时候,就直接把分享的图片,设置成为这张imageView.但是要注意的是,使用友盟分享的时候,需要注意截图的大小,太大了,可能分享不成功。

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <pre name="code" class="objc">-(UIImage *)getImageWithFullScreenshot   
  2. {    
  3.     BOOL ignoreOrientation = SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0");    
  4.         
  5.     UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;    
  6.         
  7.     CGSize imageSize = CGSizeZero;    
  8.     if (UIInterfaceOrientationIsPortrait(orientation) || ignoreOrientation)    
  9.         imageSize = [UIScreen mainScreen].bounds.size;    
  10.     else    
  11.         imageSize = CGSizeMake([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width);    
  12.         
  13.     UIGraphicsBeginImageContextWithOptions(imageSize, NO, [UIScreen mainScreen].scale);    
  14.     CGContextRef context = UIGraphicsGetCurrentContext();    
  15.         
  16.     for (UIWindow *window in [[UIApplication sharedApplication] windows])    
  17.     {    
  18.         CGContextSaveGState(context);    
  19.         CGContextTranslateCTM(context, window.center.x, window.center.y);    
  20.         CGContextConcatCTM(context, window.transform);    
  21.         CGContextTranslateCTM(context, -window.bounds.size.width * window.layer.anchorPoint.x, -window.bounds.size.height * window.layer.anchorPoint.y);    
  22.             
  23.         // Correct for the screen orientation    
  24.         if(!ignoreOrientation)    
  25.         {    
  26.             if(orientation == UIInterfaceOrientationLandscapeLeft)    
  27.             {    
  28.                 CGContextRotateCTM(context, (CGFloat)M_PI_2);    
  29.                 CGContextTranslateCTM(context, 0, -imageSize.width);    
  30.             }    
  31.             else if(orientation == UIInterfaceOrientationLandscapeRight)    
  32.             {    
  33.                 CGContextRotateCTM(context, (CGFloat)-M_PI_2);    
  34.                 CGContextTranslateCTM(context, -imageSize.height0);    
  35.             }    
  36.             else if(orientation == UIInterfaceOrientationPortraitUpsideDown)    
  37.             {    
  38.                 CGContextRotateCTM(context, (CGFloat)M_PI);    
  39.                 CGContextTranslateCTM(context, -imageSize.width, -imageSize.height);    
  40.             }    
  41.         }    
  42.             
  43.         if([window respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])    
  44.             [window drawViewHierarchyInRect:window.bounds afterScreenUpdates:NO];    
  45.         else    
  46.             [window.layer renderInContext:UIGraphicsGetCurrentContext()];    
  47.             
  48.         CGContextRestoreGState(context);    
  49.     }    
  50.         
  51.     UIImage *image = UIGraphicsGetImageFromCurrentImageContext();    
  52.         
  53.     UIGraphicsEndImageContext();    
  54.         
  55.     return image;    
  56. }  

 
 
第三方sdk:  点击打开链接

关于分享的代码: 我这儿就不贴了:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值