的UIImageView伸展在iOS 8的故事板自动布局
问题描述:
我UIImageView
工作完美,但它被拉伸其UITableViewCell
的UIImageView伸展在iOS 8的故事板自动布局
之外,我甩开了Instagram的API,这是612x612标准分辨率照片。我需要把它放在UIImageView
的自定义UITableViewCell
中,它将使用自动布局来更改每个设备的UIImageView
的尺寸。
我不确定这是如何在Xcode 6 iOS 8中工作的,因为我试过的东西到目前为止还没有工作,因为图像只是在设备视图的范围之外伸展。
任何帮助将不胜感激,谢谢!
CustomTableViewCell.m
- (void)layoutSubviews {
[super layoutSubviews];
[self.imageViewPic setTranslatesAutoresizingMaskIntoConstraints:YES];
}
ViewController.m
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 600.0;
NSString *imageURL = [NSString stringWithFormat:@"%@", standardResolutionLocal.url];
__weak MWebListTableViewCellTwo *mCell = api2Cell;
[mCell.imageViewPic
sd_setImageWithURL:[NSURL URLWithString:imageURLInstagram]
placeholderImage:[UIImage imageNamed:@"placeholder"]];
答
基于自动布局动态小区heught使用时,我注意到的UIImageView问题。视图布局良好,但图像本身并不像“contentMode”属性所定义的那样拉伸。
在显示之前强制显示单元格的布局,以某种方式修复它,但在选择之后它又回到非拉伸版本,因此需要做更多的工作。 UITableView的可能的子类将完成这项工作。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell layoutIfNeeded];
}
真棒,有道理,谢谢! – SRMR 2014-11-27 00:26:03