为什么不自动版式照顾我UICollectionView的 [英] Why is AutoLayout not taking care of my UICollectionView

查看:111
本文介绍了为什么不自动版式照顾我UICollectionView的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用内置的应用程序非常简单的示例(来源$ C ​​$ C在 github上)一个 UICollectionView

I have built a very simple sample of an app (Source code on github) using a UICollectionView.

一切工作正常,只要应用程序是在纵向模式。当它被然而改变为横向模式,内容细胞没有适当地调整大小,并且因此,什么也不显示。

Everything is working fine, as long as the app is in portrait mode. When it is changed to landscape mode however, the content cell is not resized appropriately, and thus, nothing is displayed.

我认为所有必要的自动版式的约束到位。我知道我可以实现的CollectionView:布局:sizeForItemAtIndexPath:,但我的目标是使用自动版式尽可能(简单地理解自动版式更好)

I thought that all the necessary AutoLayout constraints are in place. I am aware that I can implement collectionView:layout:sizeForItemAtIndexPath:, but my goal is to use AutoLayout as much as possible (simply to understand AutoLayout better).

我是什么在这里失踪?

推荐答案

您可以使用自动布局来设置集合视图的位置和大小。你也可以使用自动布局来设置每个小区内的子视图的位置和大小。但是,不能使用自动布局来控制细胞的位置和大小。您必须使用集合视图的布局对象设置每个集合视图单元格的位置和大小。如果您希望在接口的方向改变细胞改变大小,你必须更新你的布局对象报告新的大小和布局失效。

You can use autolayout to set the position and size of the collection view. And you can use autolayout to set the position and size of the subviews inside each cell. But you cannot use autolayout to control the position and size of the cells. You must use the collection view's layout object to set the position and size of each collection view cell. If you want the cells to change size when the interface orientation changes, you must update your layout object to report the new size and invalidate the layout.

这篇关于为什么不自动版式照顾我UICollectionView的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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