0

我有一个SlackTextViewController带有自定义的表格视图 (),UITableViewCell其中包含一个UIImageView和一个UITextView。我SDWebImage用于缓存和设置图像。

这是我的cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *identifier = @"CommentsCell";

    CommentsCell *cell =(CommentsCell *) [self.tableView dequeueReusableCellWithIdentifier:identifier];

    if (!cell) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:identifier owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }        

    commentsModel =(CommentsModel *)commentsListArray[indexPath.row];

    if (commentsModel.hasImage) {    
        cell.imageHeight.constant=150;
        cell.photoImageView.hidden = NO;

        NSString *imageUrl = commentsModel.commentImage;
        [cell.photoImageView setShowActivityIndicatorView:YES];
        [cell.photoImageView setIndicatorStyle:UIActivityIndicatorViewStyleGray];

        cell.photoImageView.contentMode = UIViewContentModeScaleAspectFill;
        [cell.photoImageView sd_setImageWithURL:[NSURL URLWithString:imageUrl]];    
    } else  {
        cell.imageHeight.constant=0;
        cell.photoImageView.hidden = YES;
        cell.textview.text=commentsModel.comments;
        [cell.textview sizeToFit];                
    }

    cell.transform = self.tableView.transform;
    return cell

}

第一次打开视图控制器时,imageView 的内容模式以某种方式设置为ScaleAspectFit,当我上下滚动几次时,内容模式正确设置为ScaleAspectFill.

初始内容模式状态:

初始内容模式状态

上下滚动一些后:

上下滚动一些后

发生的另一件奇怪的事情是,当我展示 a 时UIAlertController,imageView 的内容模式突然变为动画,ScaleAspectFill如下面的视频所示:

https://www.youtube.com/watch?v=OT3bUR4CR5c&feature=youtu.be

  • 我没有ScaleAspectFit意外地将内容模式更改为代码中的任何位置。
  • 我检查了视图层次结构,发现 imageView 的宽度和高度没有变化,而且我没有在任何地方更改它的框架。
  • 我尝试在prepareForReuse自定义单元格的方法中设置内容模式。
  • 我尝试在主线程中设置图像。

以上都不能解决问题。任何帮助,将不胜感激。谢谢。

4

0 回答 0