相关疑难解决方法(0)

具有自动布局的UICollectionViewCell动态高度

我正在使用UICollectionViewCell的自动布局.因此,我们的想法是允许CollectionViewCell根据布局确定它的大小.所有约束都设置正确,但问题是我无法计算数据源方法的大小

collectionView:layout:sizeForItemAtIndexPath:
Run Code Online (Sandbox Code Playgroud)

理想情况下,我想计算Cell的高度,执行以下操作:

static MyCell *myCell = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    myCell = [[MyCell alloc] initWithFrame:CGRectZero];
});
cell.model = model;
[cell updateConstraints];
[cell layoutSubviews];
return cell.frame.size;
Run Code Online (Sandbox Code Playgroud)

但它不会强制更新约束,因此单元格的框架为零.你能建议我如何根据它的约束来计算细胞的大小?

谢谢

autolayout uicollectionview nslayoutconstraint uicollectionviewcell

10
推荐指数
2
解决办法
2万
查看次数