博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
计算图片的宽和高 动态设置图片的位置
阅读量:6673 次
发布时间:2019-06-25

本文共 3962 字,大约阅读时间需要 13 分钟。

  切记 : 计算图片的高度和宽度应该在请求数据的时候获取.然后保存起来 否则的话会造成卡顿现象     
 
方法优化:
    WidthAndHeight *wAndH = _widthAndHeightDataArray[indexPath.row];
   
    CGFloat width = wAndH.widthPic;
   
    CGFloat height = wAndH.heightPic;
   
    CGRect picBackViewFrame = cell.picBackView.frame;
    cell.picBackView.frame = CGRectMake(0, picBackViewFrame.origin.y, SCREEN_WIDTH, SCREEN_WIDTH);
    cell.postPhoto.frame = CGRectMake(width / 2 > SCREEN_WIDTH ? 0 : ((SCREEN_WIDTH - width / 2) / 2), height / 2 > SCREEN_WIDTH ? 0 : ((SCREEN_WIDTH - height / 2) / 2), width / 2 > SCREEN_WIDTH ? SCREEN_WIDTH : (width / 2), height / 2 > SCREEN_WIDTH ? SCREEN_WIDTH : (height / 2));
 
以下舍弃
#pragma  mark - requestMore
- (void)requestMore {
    [API selectNoteContentFrom:from to:to completion:^(NSError *error, id responseData) {
        if (!error) {
           
            for (NSDictionary *dic in responseData[@"result"]) {
                FindContent *find = [[FindContent alloc] init];
                [find setValuesForKeysWithDictionary:dic];
               
                UIImage *image = [[UIImage alloc] initWithData:[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:find.imgList[0]]]];
                WidthAndHeight *wAndH = [[WidthAndHeight alloc] init];
                CGFloat width  = image.size.width;
                CGFloat height = image.size.height;
                wAndH.widthPic = width;
                wAndH.heightPic = height;
                [_widthAndHeightDataArray addObject:wAndH];
                NSLog(@"**************************************%@", wAndH);
                [_noteArray addObject:find];
            }
            [self.tableView reloadData];
        }
    }];
}
UIView*picBacgroundView;
        UIImageView *contentPic;
        for (int i = 0; i < imgArray.count; i++) {
       
    WidthAndHeight *wAndH = _widthAndHeightDataArray[indexPath.row];
   
    CGFloat width = wAndH.widthPic;
   
    CGFloat height = wAndH.heightPic;
            if (iPhone4) {
                if (width / 2 > SCREEN_WIDTH) {
                    picBacgroundView.frame = CGRectMake(0, photoImage.frame.origin.y + photoImage.frame.size.height + 10 + SCREEN_WIDTH * i + 10 * i, SCREEN_WIDTH, SCREEN_WIDTH);
                    contentPic.frame = CGRectMake(0, 0 , SCREEN_WIDTH, SCREEN_WIDTH);
                } else {
                    picBacgroundView.frame = CGRectMake(0, photoImage.frame.origin.y + photoImage.frame.size.height + 10 + SCREEN_WIDTH * i + 10 * i, SCREEN_WIDTH, SCREEN_WIDTH);
                    contentPic.frame = CGRectMake((SCREEN_WIDTH - width / 2) / 2, (SCREEN_WIDTH - height / 2) / 2 , width / 2, height / 2);
                }
            } else if (iPhone5) {
                if (width / 2 > SCREEN_WIDTH) {
                    picBacgroundView.frame = CGRectMake(0, photoImage.frame.origin.y + photoImage.frame.size.height + 10 + SCREEN_WIDTH * i + 10 * i, SCREEN_WIDTH, SCREEN_WIDTH);
                    contentPic.frame = CGRectMake(0, 0 , SCREEN_WIDTH, SCREEN_WIDTH);
                } else {
                    picBacgroundView.frame = CGRectMake(0, photoImage.frame.origin.y + photoImage.frame.size.height + 10 + SCREEN_WIDTH * i + 10 * i, SCREEN_WIDTH, SCREEN_WIDTH);
                    contentPic.frame = CGRectMake((SCREEN_WIDTH - width / 2) / 2, (SCREEN_WIDTH - height / 2) / 2 , width / 2, height / 2);
                }
            } else if (iPhone6) {
                if (width / 2 > SCREEN_WIDTH) {
                    picBacgroundView.frame = CGRectMake(0, photoImage.frame.origin.y + photoImage.frame.size.height + 10 + SCREEN_WIDTH * i + 10 * i, SCREEN_WIDTH, SCREEN_WIDTH);
                    contentPic.frame = CGRectMake(0, 0 , SCREEN_WIDTH, SCREEN_WIDTH);
                } else {
                    picBacgroundView.frame = CGRectMake(0, photoImage.frame.origin.y + photoImage.frame.size.height + 10 + SCREEN_WIDTH * i + 10 * i, SCREEN_WIDTH, SCREEN_WIDTH);
                    contentPic.frame = CGRectMake((SCREEN_WIDTH - width / 2) / 2, (SCREEN_WIDTH - height / 2) / 2 , width / 2, height / 2);
                }
            } else {
                picBacgroundView.frame = CGRectMake(0, photoImage.frame.origin.y + photoImage.frame.size.height + 10 + SCREEN_WIDTH * i + 10 * i, SCREEN_WIDTH, SCREEN_WIDTH);
                contentPic.frame = CGRectMake((SCREEN_WIDTH - width / 2) / 2, (SCREEN_WIDTH - height / 2) / 2 , width / 2, height / 2);
            }
            [contentPic sd_setImageWithURL:[NSURL URLWithString:self.findContent.imgList[i]]];
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pressPic:)];
            [contentPic addGestureRecognizer:tap];
            contentPic.userInteractionEnabled = YES;
            [picBacgroundView addSubview:contentPic];
        }

转载于:https://www.cnblogs.com/tian-sun/p/5019944.html

你可能感兴趣的文章
ClassUtil
查看>>
Elastic-Job定时任务
查看>>
真实分享记录我学习Linux系统遇到的问题
查看>>
Linux下查找占用内存最多的进程
查看>>
mongodb 配置文件
查看>>
查看 docker 容器使用的资源
查看>>
Jedis的配置和优化
查看>>
layui + 阿里巴巴iconfont图标库导入
查看>>
2017总结一
查看>>
Spring boot 入门--1
查看>>
MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法
查看>>
Power Designer数据库建模工具,正向、逆向工程
查看>>
Libevent学习-02:搭建CentOS下的开发环境
查看>>
java操作Excel、word和pdf
查看>>
阿里巴巴常考面试题及汇总答案
查看>>
yum install 与 yum groupinstall 的区别
查看>>
Docker Swarm 编排及部署 PostGIS,并操作 GIS 数据
查看>>
当区块链遇上人工智能,这次变革的意义到底有多重大?
查看>>
Linux下安装python
查看>>
Go基础系列:读取标准输入(一)
查看>>