CALayer+VQ_OCBarrage.m 851 B

12345678910111213141516171819202122232425262728
  1. //
  2. // CALayer+VQ_OCBarrage.m
  3. // OCBarrage
  4. //
  5. // Created by QMTV on 2017/8/29.
  6. // Copyright © 2017年 LFC. All rights reserved.
  7. //
  8. #import "CALayer+VQ_OCBarrage.h"
  9. @implementation CALayer (OCBarrage)
  10. - (UIImage *)youpaifconvertContentToImageWithSize:(CGSize)contentSize {
  11. // 传入的View.frame.size是0的话,直接返回nil,防止 UIGraphicsBeginImageContext() 传入0,导致崩溃
  12. if (CGSizeEqualToSize(contentSize, CGSizeZero)) {
  13. return nil;
  14. }
  15. UIGraphicsBeginImageContextWithOptions(contentSize, 0.0, [UIScreen mainScreen].scale);
  16. //self为需要截屏的UI控件 即通过改变此参数可以截取特定的UI控件
  17. [self renderInContext:UIGraphicsGetCurrentContext()];
  18. UIImage *image= UIGraphicsGetImageFromCurrentImageContext();
  19. UIGraphicsEndImageContext();
  20. return image;
  21. }
  22. @end