I've a stack view inside scroll view as shown in the image below. I want to align it vertically in center. It doesn't align vertically in center on iPhone 5S, it works fine on iPhone 11 Pro Max. I've seen this solution https://stackoverflow.com/a/50767533/12114641 and my implementation is exactly same. How do I fix it so that i aligns vertically in center on all devices?
Asked
Active
Viewed 424 times
1
-
"except that I'm not able to do following: change contentView height constraint to Priority: 250" Why are you not able to do that? Is it because you have no height constraint? It looks to me like you do have one. – matt May 15 '20 at 23:39
-
I've followed the solution again, I can see that he has set contentView equal height to ScrollView, I always set it to outer view that's why I missed it, Anyways I've set the height for contentView and changed it's priority to 250 but I'm still having same issue. Stack view doesn't align vertically in center on iPhone 5S. I've also update screenshot. – Raymond May 15 '20 at 23:47
-
@Raymond = A little tough to know what you need to do - but most likely, since you have labels / text fields? / image views / etc embedded in views in the stack view, you need to make some Content Hugging Priority adjustments. I've tried to duplicate your layout here: https://github.com/DonMag/CenteredScroll ... the results: https://i.stack.imgur.com/fCItN.jpg – DonMag May 16 '20 at 00:38
-
@DonMag thanks for taking so much effort to create the project. I've checked your project and guess what, I found the issue. the culprit is Content Layout Guides. If it is disabled then it doesn't center, if it's enabled then it does. I've checked both yours and my project and similar behaviour. So it all comes down to "Content Layout Guides". How do we go from here? – Raymond May 16 '20 at 17:34
-
@Raymond - hmmm... I just removed the Content and Frame Layout Guides from the second tab's VC and it centers as expected. Didn't even have to re-add constraints -- IB automatically changed them to Superview. I updated my GitHub repo. – DonMag May 16 '20 at 19:05
-
Thanks, Just realised that the issue is only on simulator and not on device. Not sure why? – Raymond May 17 '20 at 20:52