Reputation: 473
I have one screen which contains two UICollectionView
, top most is for menu/options and bottom one for showing content for selected cell from top UICollectionView
. I have designed entire screen in storyboard using auto-layout and constraints.
Now my UI looks perfect in all devices except iPhoneX.
In iPhoneX
top most UICollectionView
looks good. But the UICollectionView
which is beneath top most UICollectionView
is not showing content properly. UICollectionView
is on right/proper position but its cell's (UICollectionViewCell
) content cut from top.
For debug purpose I have coloured different views with different colours and attached below.
Here Yellow coloured view is background/container view of two UICollectionView
, red coloured view is top most UICollectionView
and purple coloured view is container view which contains all the controls of UICollectionViewCell
.
Below is the debug hierarchy view of UICollectioView
and UICollectionViewCell
Below is the Debug hierarchy view of UIView
which is cut from top inside UICollectioViewCell
Upvotes: 1
Views: 941
Reputation: 1209
It is better to give the full size of your collection view to your cell:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: collectionView.frame.width, height: collectionView.frame.height)
}
but if you need to give height for your specific cell you should specify y position for your frame of cell in the cell for item at indexPath:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell: MyCell = collectionView.dequeueReusableCell(for: indexPath)
cell.frame = CGRect(x:0, y: 0, width: collectionView.frame.width, height: myHeight)
return cell
}
Upvotes: 0