问题
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.
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).
What am I missing here?
回答1:
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.
来源:https://stackoverflow.com/questions/14198392/why-is-autolayout-not-taking-care-of-my-uicollectionview