UICollectionView cells misaligned when returned from a screen transition by show Segue

Asked 2 years ago, Updated 2 years ago, 146 views

When drawing for the first time, it appears as shown in the image below, but

When I return from the show screen transition, the display will be misaligned as shown below.

I tried to play with the top bar of the inspector in view, but it didn't improve.
Autolayout seems to have nothing to do with it.
If anyone knows the cause, please let me know.


When I created a new project, I couldn't reproduce the situation, but I found something that I thought might be the cause.

The image below is part of a screenshot of the storyboard for a new project (not misaligned).The cell background on the collectionView is white.

And the following image is part of the storyboard screenshot of the existing project (shifted).

In this way, the collectionView cells are misrepresented on the storyboard in existing projects.
I tried to change the position of the cell with the inspector in the collectionView, but I couldn't.
Deleting this collectionView and placing a new collectionView did not replace it.

objective-c uicollectionview

2022-09-30 20:45

1 Answers

The situation cannot be reproduced.What I tried:

When I edited it like this, there was no phenomenon that the cell position in the collection view would change when I returned to the segment as you mentioned.
Please indicate which model the problem will always occur.

To add:
I found something interesting about the behavior of deploying UiCollectionView on the UINavigationController-based View Controller, so I'll write it down.
After placing some object (buttons in the picture below) on the base view, and then placing the UICollectionView, the Prototype Cell is located in the top left corner of the Collection View.(Picture left)

Enter a description of the image here Enter a description of the image here

After that, the Prototype Cell will shift down as soon as the button is removed.(Right picture)
Notice that the amount of deviation is equal to the height of the navigation bar.
This is a hypothesis, but if AutoLayout's Constraints are all aimed at the edge of the base view, the UICollectionView's cell position will shift by the height of the navigation bar.Other than that, it is located in the upper left corner.Isn't that kind of automatic adjustment working?
The first question in your question may be related to this.


2022-09-30 20:45

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.