After playing a bit these days with UICollectionView
, I think I understand how it works but, there's something I'm missing.
I have 8 views added to the UICollectionView
and they do not jump to the next row when they don't fit in the screen. It seems that the UICollectionView
is bigger than the screen. I had to use constraints on the UICollectionView
to make it same width and height of the parent view.
Here some screenshots:
Without Constraints:
With Constraints:
Could anyone explain this behaviour?
答案 0 :(得分:0)
If you don't set constraints on a view in Storyboard, it will retain its dimensions as specified in the Storyboard - it will not automatically resize with superview
. So the fact that the root view of UIViewCntroller
was resized to fit the screen does not affect size of UICollectionView
.
As you have been creating your UICollectionView
in universal size it ended up much bigger that actual screen.
To answer your follow-up questions in the comments:
At the runtime will persist constants of it's width and height, not relation to the size of it's parent (Unless you specify otherwise).
When UIViewController
is shown, (in most cases) it's root view is resized to fit the screen. However, it's children will remain unchanged, unless you specify otherwise.
By universal size I meant the size of UIViewController
in the storyboard as you specify in Attribute Inspector -> Size -> Freeform
, which defaults to 600x600
. I suppose "freeform" would be more correct than "universal".