给tableView 截个图 只要cell的截图


        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;

    


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值