我在Storyboard中有我的ViewController。在Storyboard中一切似乎都很好,但是当我在模拟器上构建它时,它会在侧面显示奇怪的白色位置。当我将视图的背景更改为蓝色时,我意识到白色空间是由我的视图引起的。什么会导致这种问题?
答案 0 :(得分:0)
Make sure your scrollViews and contentViews LeadingSpace and TrailingSpace are 0, It seems you are leaving 20 pts from LeadingSpace and TrailingSpace.
Your constraints should look like this:
Make sure you set MainView/ContentView width equals to scrollView.
What you are messing is, you are setting scrollView width equal to ViewControllers View, remove that constraint and it should work hopefully.
Edit/Update:
I have done demo for test and it is working perfectly fine without any workaround. You can see below screen shot of Storyboard Preview for iPhone 5S and iPhone 6S Plus. ViewControllers view is in Blue color and ContainerView is in Orange color.
Here are the constraint of scrollView: (While adding constraint make sure you press Alt button)
And the ScrollViews constraint are as below:
ContainerView Contraints:
And the ContainerViews constraint are as below:
One last thing, inside container view all view's should have top to bottom constraint in order to calculate the height required for scrollView. And also do not create conflicting constraints as - Setting imageView's LeadingSpace and TrailingSpace to ContainerView(SuperView) and at the same time setting fix width.