【问题标题】:Images in a CustomTableCell gets resized upon clickCustomTableCell 中的图像在单击时调整大小
【发布时间】:2015-09-11 07:36:49
【问题描述】:

如果没有项目,这将无法解释,因此我在 GitHub 上上传了一个小的 DEMO

我不认为约束是错误的。图像应固定在其位置。最初SDWebImage 从缓存中检索图像,但是一旦我单击图像,图像就会调整大小。 (它变小了,见上图)

有趣的是,在我的演示中,图像首先显示为红色方块。单击它们后,imageView 会调整大小并加载实际图像。但这仍然显示了问题。

在我看来,初始缓存没有根据约束调整大小。这是真的吗?

【问题讨论】:

    标签: ios ios8 xcode6.1 sdwebimage


    【解决方案1】:

    我试过你的代码

     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BookmarkTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:bookmarkcellIdentifier forIndexPath:indexPath];
    
    News *news = [_news objectAtIndex:indexPath.row];
    cell.headLine.text = news.headLine;
    
    [cell.newsImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",news.imageUrlList]] placeholderImage:[UIImage imageNamed:@"iTagImageHolder"]];
     [cell.newsImage.layer setBorderWidth: 2.0];
    [cell.newsImage.layer setBorderColor: [[UIColor blackColor] CGColor]];
    
    
    return cell;
    }
    

    我得到了像

    这样的输出

    在情节提要中,我在“属性检查器”中选择Autoresize subviews

    【讨论】:

    • 否则检查你是否在任何地方更改了图像框架
    • 对不起,它不起作用。随意克隆我的 github 演示并试一试。谢谢
    • @Houman - 检查更新的答案,在这里我检查以选择图像并滚动它完美显示的表格,任何问题
    • 抱歉迟到了评论。不幸的是它不起作用。如果您查看红色图像支架,它仍然是不同的尺寸。一旦您单击图像并加载它,它就会再次变成不同的大小。我们如何阻止 ImageView 调整大小?
    【解决方案2】:

    这解决了它:

    [cell.imageView sd_setImageWithURL:imageURL
                          placeholderImage: nil
                                 completed:^(UIImage image, NSError error, SDImageCacheType cacheType, NSURL *imageURL) {
                                     [cell setNeedsLayout];
                                 }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-18
      • 1970-01-01
      • 2017-05-04
      • 2010-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多