给tableView 截个图 只要cell的截图
2016-01-29 12:01
477 查看
self.tableView.userInteractionEnabled =NO;//暂时禁用交互,让tableView自己滑动
//
生成保存的单个图片先存入array
NSMutableArray * imageArr = [NSMutableArrayarray];
//
将tableView滚动至第一个cell的位置,确保第一组cell全部可见
[self.tableViewsetContentOffset:CGPointMake(0,150)
animated:NO];
for (NSInteger i =0; i <
6; i++) {
NSIndexPath * indexPath = [NSIndexPathindexPathForRow:i
inSection:0];
//
将cell一个一个渲染成图片
LJFallDownSectionOneCell * cell = [self.tableViewcellForRowAtIndexPath:indexPath];
UIGraphicsBeginImageContext(cell.frame.size);
[cell.layerrenderInContext:UIGraphicsGetCurrentContext()];
UIImage * image =UIGraphicsGetImageFromCurrentImageContext();
if (image) {
[imageArr addObject:image];
}
UIGraphicsEndImageContext();
LJLog(@"aaa%ld",imageArr.count);
}
// 第二组全部可见后开始渲染
[UIViewanimateWithDuration:3.0animations:^{
[self.tableViewscrollToRowAtIndexPath:[NSIndexPathindexPathForRow:0inSection:1]atScrollPosition:UITableViewScrollPositionTopanimated:NO];//
animated 必须为NO,否则和UIView
animateWithDuration冲突
} completion:^(BOOL finished) {//动画完成后开始渲染
if (finished) {
for (NSInteger j =0; j <
10; j ++) {
NSIndexPath * indexPath = [NSIndexPathindexPathForRow:j
inSection:1] ;
LJFallDownSectionOneCell * cell = [self.tableViewcellForRowAtIndexPath:indexPath];
UIGraphicsBeginImageContext(cell.frame.size);
[cell.layerrenderInContext:UIGraphicsGetCurrentContext()];
UIImage * image =UIGraphicsGetImageFromCurrentImageContext();
if (image) {
[imageArr addObject:image];
}
UIGraphicsEndImageContext();
LJLog(@"bbb%ld",imageArr.count);
}
// start
//将所有小图片拼成一张大图片
// 先计算出大图片的大小
CGFloat totalH =
0;
for (UIImage * imagein imageArr) {
totalH += image.size.height;
}
UIGraphicsBeginImageContext(CGSizeMake(LFScreenWidth, totalH));
CGFloat hight =
0;
for (NSInteger i =0; i < imageArr.count; i ++) {
UIImage * image = imageArr[i];
[image drawInRect:CGRectMake(0, hight,LFScreenWidth, image.size.height)];
hight += image.size.height;
}
UIImage * bigImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
/// 存入沙盒
NSData * imageData =
UIImagePNGRepresentation(bigImage);
NSString * filePath =NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,
YES)[0];
NSString * imagePath = [filePathstringByAppendingString:@"/history.png"];
BOOL flag= [imageData
writeToFile:imagePath atomically:YES];
if (flag) {
LJLog(@"存入图片成功");
}else{
LJLog(@"存入图片失败");
}
[MBProgressHUD
showSuccess:@"保存成功"toView:self.view];
// end
}
}];
self.tableView.userInteractionEnabled =YES;
//
生成保存的单个图片先存入array
NSMutableArray * imageArr = [NSMutableArrayarray];
//
将tableView滚动至第一个cell的位置,确保第一组cell全部可见
[self.tableViewsetContentOffset:CGPointMake(0,150)
animated:NO];
for (NSInteger i =0; i <
6; i++) {
NSIndexPath * indexPath = [NSIndexPathindexPathForRow:i
inSection:0];
//
将cell一个一个渲染成图片
LJFallDownSectionOneCell * cell = [self.tableViewcellForRowAtIndexPath:indexPath];
UIGraphicsBeginImageContext(cell.frame.size);
[cell.layerrenderInContext:UIGraphicsGetCurrentContext()];
UIImage * image =UIGraphicsGetImageFromCurrentImageContext();
if (image) {
[imageArr addObject:image];
}
UIGraphicsEndImageContext();
LJLog(@"aaa%ld",imageArr.count);
}
// 第二组全部可见后开始渲染
[UIViewanimateWithDuration:3.0animations:^{
[self.tableViewscrollToRowAtIndexPath:[NSIndexPathindexPathForRow:0inSection:1]atScrollPosition:UITableViewScrollPositionTopanimated:NO];//
animated 必须为NO,否则和UIView
animateWithDuration冲突
} completion:^(BOOL finished) {//动画完成后开始渲染
if (finished) {
for (NSInteger j =0; j <
10; j ++) {
NSIndexPath * indexPath = [NSIndexPathindexPathForRow:j
inSection:1] ;
LJFallDownSectionOneCell * cell = [self.tableViewcellForRowAtIndexPath:indexPath];
UIGraphicsBeginImageContext(cell.frame.size);
[cell.layerrenderInContext:UIGraphicsGetCurrentContext()];
UIImage * image =UIGraphicsGetImageFromCurrentImageContext();
if (image) {
[imageArr addObject:image];
}
UIGraphicsEndImageContext();
LJLog(@"bbb%ld",imageArr.count);
}
// start
//将所有小图片拼成一张大图片
// 先计算出大图片的大小
CGFloat totalH =
0;
for (UIImage * imagein imageArr) {
totalH += image.size.height;
}
UIGraphicsBeginImageContext(CGSizeMake(LFScreenWidth, totalH));
CGFloat hight =
0;
for (NSInteger i =0; i < imageArr.count; i ++) {
UIImage * image = imageArr[i];
[image drawInRect:CGRectMake(0, hight,LFScreenWidth, image.size.height)];
hight += image.size.height;
}
UIImage * bigImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
/// 存入沙盒
NSData * imageData =
UIImagePNGRepresentation(bigImage);
NSString * filePath =NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,
YES)[0];
NSString * imagePath = [filePathstringByAppendingString:@"/history.png"];
BOOL flag= [imageData
writeToFile:imagePath atomically:YES];
if (flag) {
LJLog(@"存入图片成功");
}else{
LJLog(@"存入图片失败");
}
[MBProgressHUD
showSuccess:@"保存成功"toView:self.view];
// end
}
}];
self.tableView.userInteractionEnabled =YES;
相关文章推荐
- JavaScript学习总结之JS、AJAX应用
- PostgreSQL新手入门
- 滚动周(30天)
- cocos2d-js在web使用时,一定要把资源加入到resource.js里面~~否则各种bug
- wordpress网站打开速度优化压缩html代码
- MySQL中的系统参数
- 使用技巧Windows
- JSON和JS对象之间的互转
- iOS9.1 判断定位是否可用 并定位自己位置
- Javascript 和 json 使用Ajax
- PowerVR 7架构解析
- JS获取url参数及url编码、解码
- 9.5 在 C# 中使用 F# 库
- sql server2008本地连接选择windows身份验证无法登陆的解决办法
- Socket send函数和recv函数详解
- php学习之道:WSDL具体解释(三)
- java常用功能
- .NET——Random类
- PHP——0128练习相关1——window.open()
- 数组、字符串长度的计算