Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is AutoLayout not taking care of my 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.

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?

like image 348
below Avatar asked Jan 07 '13 14:01

below


1 Answers

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.

like image 152
rob mayoff Avatar answered Sep 30 '22 18:09

rob mayoff