【问题标题】:size of UITableViewCell.imageView changed with autolayoutUITableViewCell.imageView 的大小随自动布局而改变
【发布时间】:2015-11-18 13:53:04
【问题描述】:

我在 uitableview 中使用 UITableViewCell.imageView 来显示图像并且图像视图的圆角。有以下代码

[cell2.imageView setAutoresizingMask:UIViewAutoresizingNone];
cell2.imageView.backgroundColor = [UIColor whiteColor];
cell2.imageView.contentMode = UIViewContentModeScaleAspectFit;
cell2.imageView.layer.masksToBounds = YES;
cell2.imageView.clipsToBounds = YES;
cell2.imageView.layer.borderWidth = 1.0f;
cell2.imageView.layer.borderColor = [UIColor colorWithRed:(1/255.0) green:(146/255.0) blue:(219/255.0) alpha:1.0].CGColor;

[cell2.imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[ReviewArrayMain objectAtIndex:indexPath.row] valueForKey:@"logo"]]] placeholderImage:[UIImage imageNamed:@"Defaultlogo.png"] options:SDWebImageRetryFailed completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            if (error) {
                NSLog(@"Error : %@", error);
            }else{
                cell2.imageView.image  = image;
                [cell2 layoutSubviews];
                cell2.imageView.layer.cornerRadius = cell2.imageView.frame.size.height/2;
            }
}];

我在一个屏幕上得到了完美的输出,如下所示:

但在另一个具有相同代码的屏幕中,我得到以下输出:

我无法理解是什么问题?这仅发生在 iPad Only 上。在iphone中它工作得很好。

我监控的另一件事是当我在两个屏幕上打印 cell.imageview 的大小时,我得到以下日志输出:

NSLog(@"Cell.imageview size W : %f H: %f",cell.imageView.frame.size.width,cell.imageView.frame.size.height); em>

它在屏幕 A 上为我提供如下输出: Cell.imageview 大小 W 88.000000 H: 88.000000

在屏幕 B 上如下: Cell.imageview 详细尺寸 W : 44.000000 H: 44.000000

希望这个问题很好理解。

【问题讨论】:

  • 你是否限制了单元格布局?
  • 也许你应该多为 ipad 转角

标签: objective-c uitableview ipad uiimageview ios-autolayout


【解决方案1】:

首先,如果您在 TableView 的委托方法中设置圆角半径,那么请不要这样做。 取而代之的是 TableViewCell 的子类,并在其 AwakeFromNib 方法中设置角半径。这是比较合适和有效的方式。

因为 CellForRowAtIndexPath 方法调用了单元格重新加载的次数。我们需要为每个单元设置一次圆角。

请忽略任何格式,因为我在手机上。

【讨论】:

    【解决方案2】:

    试试这个:

    -(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
        return (minimun height of your cell);
    }
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        //SenderChatCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SenderChatCell"];
        return UITableViewAutomaticDimension;
    }
    

    这对我有帮助……希望对你也有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-11
      • 1970-01-01
      • 1970-01-01
      • 2018-11-24
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多