设置UICollectionViewCell大小时电池是使用自动版式 [英] Setting UICollectionViewCell size when cell is using AutoLayout

查看:113
本文介绍了设置UICollectionViewCell大小时电池是使用自动版式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UICollectionViewCell 具有动态的高度。它包含一个的UIWebView 异步加载一些内容。负载后,需要调整自身以适应其内容。

I have a UICollectionViewCell that has a dynamic height. It contains a UIWebView that loads some content asynchronously. After load, it needs to resize itself to accommodate its contents.

我通过改变 Web视图的高度约束做电池大小调整

我也发一个委托方法来收集视图控制器该小区已经调整,我需要布局无效。

I also send a delegate method to the collection view controller that the cell has resized and I need to invalidate layout.

不过,我获得关于冲突的约束自动排版错误。这似乎集合视图正试图调整单元格。

However, I am getting auto layout errors about conflicting constraints. It seems the collection view is trying to resize the cell.

有谁知道如何使这个设计工作?

Does anyone know how to make this design work?

推荐答案

一个集合视图作品布局对象指定一个明确的大小细胞。同样,以表视图,你不能真正做到从内往外细胞的布局。

A collection view works by the layout object specifying an explicit size for the cells. Similarly to table views, you can't really do the layout from the cells outward.

要实现设计你需要做的布局对象知道电池需要根据其内容的大小。有几种方法来实现这一目标,其中没有一个是巨大的。也许在你的情况下,你需要通过新的内容大小回为你无效布局的同时,并获得新的大小为索引路径回布局莫名其妙。

To implement your design you'd need to make the layout object aware of the size the cell needs to be based on its contents. There are several ways to achieve this, none of which are great. Probably in your case you'd need to pass the new content size back at the same time as you're invalidating the layout, and get the new size for that index path back to the layout somehow.

我也不会改变对你的Web视图中的高度约束。保持固定在细胞的边缘内容视图,并让其大小由从布局对象向下发送的大小来确定。这样一来,你就不会得到冲突约束。

I'd also not change the height constraint on your web view. Keep it pinned to the edges of the cells content view, and let its size be determined by the size sent down from the layout object. That way, you're not going to get clashing constraints.

这篇关于设置UICollectionViewCell大小时电池是使用自动版式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆