在ios中的一个单元格内拍摄一个屏幕

Sar*_*aur 1 screenshot objective-c uitableview ios uigraphicscontext

我试图在一个单元UITableView格内截取屏幕截图,但附加代码我只能截取单元格界限.问题在于UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f).我只能制作rect大小的截图,不能控制rect和的起源 rect = [cell bounds].所以请建议我一些想法.

{
  UITableViewCell*  cell = [self.tableView cellForRowAtIndexPath:path];
  __block  CGRect rect = [cell bounds];
  UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
  CGContextRef context = UIGraphicsGetCurrentContext();
  [cell.layer renderInContext:context];
  UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
}
Run Code Online (Sandbox Code Playgroud)

Md.*_*san 5

将screenShot作为普通screenShot拍摄,然后裁剪

-(UIImage *)cropImage:(UIImage *)image rect:(CGRect)cropRect
{
   CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);
   UIImage *img = [UIImage imageWithCGImage:imageRef]; 
   CGImageRelease(imageRef);
   return img;
}
Run Code Online (Sandbox Code Playgroud)

使用这样:

 UIImage *img = [self cropImage:viewImage rect:CGRectMake(150,150,100,100)];
Run Code Online (Sandbox Code Playgroud)

获取特定tableView Cell的框架.用这个:

CGRect myRect = [tableView rectForRowAtIndexPath:0];//example 0,1,indexPath
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.请参阅此链接 link2