1
votes

I have a UIScrollview is acting inconsistently in regards to fitting the screen width. When I run the same build over multiple times it varies from this incorrectly rendered view:

[Incorrect view]

1

to this correctly rendered view:

[Correct view]

2

When the view does render correctly the scroll works as expected but when it renders incorrectly it does not scroll at all but the image width seems to render fine.

The view hierarchy is View>Safe Area> Scroll view> Content View. I have constrained the width of Content View to equal to the top view and also setts the constrains (0,0,0,0) for scroll and Content View . The other issues is my view is going behind the top bar even though I have disable the extend edges feature in storyboard. I have also tried setting the Scroll View size in code with the following:

let size = UIScreen.main.bounds.size self.scrollView.contentSize = CGSize(width: size.width, height: size.height)

In the debugger for each render look like this. Notice that VC escapes the navigation VC

When rendered correctly

When rendered incorrectly

Any help would be appreciated

1
Have you set constraints to the left and top of the view? - Jake
yes I have... I just had I look in look in the the view hierarchy debugger and it seems that the view controller width is expanding outside the the navigator controller that it is embedded in. I am not sure why? - bradmuzza
If you correctly set your constraints, you would not need to set the height and width. - Jake
I'm not sure about this but in the first screenshot, the text below the image is single line. What I'm thinking is that its getting the intrinsic size for the multi-lined label. The space white block we see is part of that label. Try changing the backgroundColor of your elements to see which one is really having the problem. And work from there. - TheNitram
What I am thinking is that it has something to do with segueing from a tabview VC which is embed in a nav VC. Would this make a difference? When it goes back the nav VC is something does not what to comply with the nav VC constraints - bradmuzza

1 Answers

0
votes

Turns out my issue was linked to renaming the embedded VC after I created it . I had to delete the and start again and it now works fine