Mano Mano - 8 months ago 49
iOS Question

Collectionview's bottom constraints not updated in runtime

I am using a collectionView with FlowLayout. Please find the following image.

enter image description here

In the image, the white area is the collectionView. During Runtime the red color view might get hidden based on a condition. So the collectionView will have to move up. That is not an issue. That works as expected. But when the collectionView moves up, the 'All Months' button which is connected to collectionView by vertical spacing constraint of 20 pixels does not move up.

enter image description here

My requirement is that the 'All Months' button has to be 20 pixels next to the collectionView even if the collectionView changes its y position or height during runtime.

I have moved the contentView of my ScrollView upwards to show you the constraints of 'All Months' and 'Next' buttons. Pl check the following images

enter image description here
enter image description here

enter image description here

Answer Source

I am changing the whole answer after looking and editing your project, here you go with the edited link which i forked from your project:

The thing I have Changed:

  1. Content View inside your scrollview its height constraints priority is changed to 250(low priority) as it was not getting shorter if your orange view gets hidden.

  2. In your viewWillAppear() I added self.view.layoutIfNeeded() and commented out the inner code of viewDidLayoutSubviews() (you can reopen the code as your needs)

I have checked it and its working as needed. Please do check that project in the link I provided and let me know.