当点击iOS SDK中的单元格时,如何从tableviewcell获取图像(使用CGContext) [英] How to get image( using CGContext ) from the tableviewcell when tapped on the cell in iOS SDK

查看:65
本文介绍了当点击iOS SDK中的单元格时,如何从tableviewcell获取图像(使用CGContext)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用与我点击的tableviewcell相同的CGContext进行成像。我得到了我拍摄的细胞框架。我看过很多CGContext的例子,它只把大小作为输入并将图像转换成那个大小。

How to get imaged using CGContext same as the tableviewcell that I Tapped. I got the frame of the cell which I tapped. I had seen many examples of CGContext it only takes the size as the input and converting the image into that size.

但我想得到tableviewcell的图像,因为它具有相同的框架。任何人都可以建议我怎样才能做到这一点。

But I want to get the Image of the tableviewcell as it is with the same frame. Can anyone suggest me how can I do this.

推荐答案

我猜你需要在你的手机后的适当位置加入这两个逻辑正在被挖掘。
有一个方法 - (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath; 来获取 CGRect 当前单元格。

I guess You need to club these two logic in appropriate place after your cell is being tapped. There is a method - (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath; to get the CGRect of your current cell.


  1. 查找 CGRect > UITableViewCell 被点击。

  2. 获取 CGSzie 步骤1的CGRect

  1. Find the CGRect of the UITableViewCell being clicked.
  2. Get the CGSzie from the CGRect of step 1.

-(UIImage *) screenshot:(CGRect )cellRect onCell:(UITableViewCell)cell
 {
   UIGraphicsBeginImageContext(cellRect.size);

   CGContextRef context=UIGraphicsGetCurrentContext();
   [cell.layer renderInContext:context];

   UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
   UIGraphicsEndImageContext();

   return image;
 }


这应该可以解决你的问题问题,可能需要一些调整。

This should solve your problem, may need a few tweaks.

这是用法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

UIImageView *imageV = [[UIImageView alloc]initWithImage:[self screenshot:[tableView rectForRowAtIndexPath:indexPath] onCell:[tableView cellForRowAtIndexPath:indexPath]]];
imageV.frame = CGRectMake(0, 75, self.tableView.frame.size.width,100);

UIViewController *viewController = [[UIViewController alloc]init];
[viewController.view addSubview:imageV];

UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];
[self presentViewController:nav animated:YES completion:^{
}];

}

屏幕:选定的第1行

将图像视图加载到新视图控制器上

Loaded the image view onto new view controller

这篇关于当点击iOS SDK中的单元格时,如何从tableviewcell获取图像(使用CGContext)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆